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
2 changes: 1 addition & 1 deletion src/extension/common/variables/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ function parseEnvLine(line: string): [string, string] {
// We don't use dotenv here because it loses ordering, which is
// significant for substitution.
// Modified to handle multiline values by using 's' flag so $ matches before newlines in multiline strings
const match = line.match(/^\s*(_*[a-zA-Z]\w*)\s*=\s*(.*?)?\s*$/s);
const match = line.match(/^\s*(_*[a-zA-Z][\w/]*)\s*=\s*(.*?)?\s*$/s);
if (!match) {
return ['', ''];
}
Expand Down
17 changes: 17 additions & 0 deletions src/test/unittest/common/environment.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,21 @@ suite('Environment File Parsing Tests', () => {
expect(result.VAR1).to.equal('value1');
expect(result.VAR2).to.equal('multiline\nvalue');
});

test('Should parse keys containing forward slashes (e.g. Consul-style namespaced variables)', () => {
const content = 'routes/my_service=http://localhost:8080\nservices/db/host=localhost';
const result = parseEnvFile(content);

expect(result['routes/my_service']).to.equal('http://localhost:8080');
expect(result['services/db/host']).to.equal('localhost');
});

test('Should parse mixed standard and slash-namespaced keys in the same file', () => {
const content = 'STANDARD_VAR=value1\nroutes/my_service=http://localhost:8080\nANOTHER_VAR=value2';
const result = parseEnvFile(content);

expect(result['STANDARD_VAR']).to.equal('value1');
expect(result['routes/my_service']).to.equal('http://localhost:8080');
expect(result['ANOTHER_VAR']).to.equal('value2');
});
});
Loading