mirror of https://github.com/laurent22/joplin.git
Server: Disallow loading env file that contains duplicate keys
parent
c0501fc4e0
commit
9d16dd22be
|
@ -99,7 +99,14 @@ async function main() {
|
|||
|
||||
const envFilePath = await getEnvFilePath(env, argv);
|
||||
|
||||
const envFromFile = envFilePath ? parseEnvFile(envFilePath) : {};
|
||||
let envFromFile: Record<string, string> = {};
|
||||
|
||||
try {
|
||||
if (envFilePath) envFromFile = parseEnvFile(envFilePath);
|
||||
} catch (error) {
|
||||
error.message = `Could not parse env file at ${envFilePath}: ${error.message}`;
|
||||
throw error;
|
||||
}
|
||||
|
||||
const fullEnv = {
|
||||
...envFromFile,
|
||||
|
|
|
@ -9,6 +9,7 @@ export interface Options {
|
|||
overwrite?: boolean;
|
||||
raise?: boolean;
|
||||
logger?: typeof console;
|
||||
allowDuplicateKeys?: boolean;
|
||||
}
|
||||
|
||||
export const parseEnvFile = (env_file: string, options: Options = {}) => {
|
||||
|
@ -17,6 +18,7 @@ export const parseEnvFile = (env_file: string, options: Options = {}) => {
|
|||
overwrite: false,
|
||||
raise: true,
|
||||
verbose: false,
|
||||
allowDuplicateKeys: false,
|
||||
...options,
|
||||
};
|
||||
|
||||
|
@ -101,6 +103,8 @@ export const parseEnvFile = (env_file: string, options: Options = {}) => {
|
|||
// remove ' and " characters if right side of = is quoted
|
||||
const env_value = key_value[2].match(/^(['"]?)([^\n]*)\1$/m)[2];
|
||||
|
||||
if ((env_key in data[env_file]) && !options.allowDuplicateKeys) throw new Error(`Found duplicate key: ${env_key}`);
|
||||
|
||||
if (options.overwrite) {
|
||||
data[env_file][env_key] = env_value;
|
||||
|
||||
|
|
Loading…
Reference in New Issue