Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion js/DotEnvParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,23 @@ class DotEnvParser {
}
}

static removeComments(str) {
if (str.includes('="')) {
if(str.endsWith('"')) {
return str;
} else {
const values = /(.*="(?:[^"\\]|\\.)*").*/.exec(str);
return values[1].replace('\\"','"');
}
} else {
return str.replace(/#.*/, '');
}
}

static parseEnvStr(str) {
str = str.trim();
str = str.replace(/^export /, '');
str = str.replace(/#.*/, '');
str = DotEnvParser.removeComments(str);
let parts = str.split('=');
let name = parts[0].trim();
let valid = new RegExp(`^${config.regex}$`).test(name);
Expand Down
15 changes: 15 additions & 0 deletions test/_classes/optionsTestObjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,21 @@ let envsub = [
flags: `--env-file ${Tmp.ENVFILE8}`.split(' ')
}
},
{
testName: '--env-file should remove quotes surrounding environment variables and let all character on it ',
preFunc: () => {
},
templateFile: Tmp.ENV_TEMPLATE_NOT_A_COMMENT_FILE,
outputContents: Tmp.ENV_TEMPLATE_NOT_A_COMMENT_FILE_EXPECTED,
options: {
envFiles: [
Tmp.ENVFILE9
]
},
cli: {
flags: `--env-file ${Tmp.ENVFILE9}`.split(' ')
}
},
{
testName: '--env-file should not substitute environment variables with invalid names',
templateFile: Tmp.ENV_INVALID_TEMPLATE_FILE,
Expand Down
7 changes: 7 additions & 0 deletions test/_classes/templateFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ const ENVFILE5 = `${envsubDir}/envFile5.env`;
const ENVFILE6 = `${envsubDir}/envFile6.env`;
const ENVFILE7 = `${envsubDir}/envFile7.env`;
const ENVFILE8 = `${envsubDir}/envFile8.env`;
const ENVFILE9 = `${envsubDir}/envFile9.env`;

const COMBINED_TEMPLATE_FILE = `${envsubDir}/templateFileCombined`;
const COMBINED_TEMPLATE_FILE_EXPECTED = readFileSync(`${envsubDir}/templateFileCombined_E`, 'utf8');

const ENV_TEMPLATE_FILE = `${envsubDir}/templateFileEnv`;

const ENV_TEMPLATE_FILE_EXPECTED = readFileSync(`${envsubDir}/templateFileEnv_E`, 'utf8');
const ENV_TEMPLATE_NOT_A_COMMENT_FILE = `${envsubDir}/templateFileNotAComment`;
const ENV_TEMPLATE_NOT_A_COMMENT_FILE_EXPECTED = readFileSync(`${envsubDir}/templateFileNotAComment_E`, 'utf8');
const ENV_FILE_TEMPLATE_FILE = `${envsubDir}/templateFileEnvFile`;
const ENV_FILE_TEMPLATE_FILE_EXPECTED = readFileSync(`${envsubDir}/templateFileEnvFile_E`, 'utf8');
const ENV_INVALID_TEMPLATE_FILE = `${envsubDir}/templateFileEnvInvalid`;
Expand Down Expand Up @@ -74,6 +78,9 @@ const templateFiles = {
ENVFILE6,
ENVFILE7,
ENVFILE8,
ENVFILE9,
ENV_TEMPLATE_NOT_A_COMMENT_FILE,
ENV_TEMPLATE_NOT_A_COMMENT_FILE_EXPECTED,
COMBINED_TEMPLATE_FILE,
COMBINED_TEMPLATE_FILE_EXPECTED,
ENV_TEMPLATE_FILE,
Expand Down
1 change: 1 addition & 0 deletions test/envsub-global/envFile9.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NOT_A_COMMENT="Daniel#not_a_comment\"" #comment
2 changes: 2 additions & 0 deletions test/envsub-global/templateFileNotAComment
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
xxx${ NOT_A_COMMENT }xxx xxx${ NOT_A_COMMENT }xxx
xxx${NOT_A_COMMENT}xxx xxx${ NOT_A_COMMENT }xxx
2 changes: 2 additions & 0 deletions test/envsub-global/templateFileNotAComment_E
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
xxxDaniel#not_a_comment"xxx xxxDaniel#not_a_comment"xxx
xxxDaniel#not_a_comment"xxx xxxDaniel#not_a_comment"xxx