Skip to content

Commit 0eff1a1

Browse files
committed
fixed dotenv parser
1 parent 1acc88c commit 0eff1a1

File tree

5 files changed

+28
-18
lines changed

5 files changed

+28
-18
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66

77
## [Unreleased]
88

9+
## [4.21.0]
10+
11+
### Fixed
12+
13+
- `.env` file parser. ([related](https://github.com/matepek/vscode-catch2-test-adapter/issues/501))
14+
915
## [4.20.2]
1016

1117
### Changed

package-lock.json

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"extensionDependencies": [],
5555
"dependencies": {
5656
"ansi-colors": "^4.1.3",
57+
"dotenv": "^17.2.3",
5758
"find-process": "^2.0.0",
5859
"gaze": "^1.1.3",
5960
"tslib": "^2.8.1",

src/ConfigOfExecGroup.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as pathlib from 'path';
22
import { promisify } from 'util';
33
import * as vscode from 'vscode';
4+
import * as dotenv from 'dotenv';
45

56
import { AbstractExecutable } from './framework/AbstractExecutable';
67
import * as c2fs from './util/FSWrapper';
@@ -408,22 +409,7 @@ export class ConfigOfExecGroup implements vscode.Disposable {
408409
envFromFile = readJSONSync(resolvedEnvFile.resolved.absPath);
409410
} else if (resolvedEnvFile.resolved.absPath.indexOf('.env') !== -1) {
410411
const content = readFileSync(resolvedEnvFile.resolved.absPath).toString();
411-
envFromFile = {};
412-
const lines = content.split(/\r?\n/).filter(x => {
413-
const t = x.trim();
414-
return t.length > 0 && !t.startsWith('#') && !t.startsWith('//');
415-
});
416-
lines.forEach((line: string) => {
417-
const eqChar = line.indexOf('=');
418-
if (eqChar !== -1) {
419-
let value = line.substring(eqChar + 1);
420-
if (value.startsWith('"') || value.startsWith("'")) value = value.substring(1);
421-
if (value.endsWith('"') || value.endsWith("'")) value = value.substring(0, value.length - 1);
422-
envFromFile![line.substring(0, eqChar)] = line.substring(eqChar + 1);
423-
} else {
424-
throw Error('line missing "=" in: "' + resolvedEnvFile.absPath + '"' + line);
425-
}
426-
});
412+
envFromFile = dotenv.parse(content)
427413
} else {
428414
throw Error('Unsupported file format: "' + resolvedEnvFile.absPath + '". Use only .json or .env');
429415
}

test/cpp/.vscode/settings.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
{
44
"pattern": "build-symlink/**/*.exe",
55
"gtest": {
6-
"prependTestRunningArgs": ["aa"],
7-
"prependTestDebuggingArgs": ["xx"]
6+
"prependTestRunningArgs": [
7+
"aa"
8+
],
9+
"prependTestDebuggingArgs": [
10+
"xx"
11+
]
812
},
913
"runTask": {
1014
"before": [

0 commit comments

Comments
 (0)