Skip to content
This repository was archived by the owner on May 21, 2019. It is now read-only.

Commit 554de49

Browse files
committed
Parse exported variables properly. Fixes #1102.
1 parent e5a6ba0 commit 554de49

File tree

5 files changed

+32
-5
lines changed

5 files changed

+32
-5
lines changed

src/plugins/DotEnvLoader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {Session} from "../shell/Session";
22
import {PluginManager} from "../PluginManager";
33
import * as Path from "path";
44
import {io} from "../utils/Common";
5-
import {sourceFile} from "../shell/Command";
5+
import {sourceFile} from "../shell/BuiltInCommands";
66

77
PluginManager.registerEnvironmentObserver({
88
presentWorkingDirectoryWillChange: () => void 0,

src/plugins/autocompletion_providers/Cd.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {expandHistoricalDirectory} from "../../shell/Command";
1+
import {expandHistoricalDirectory} from "../../shell/BuiltInCommands";
22
import {styles, directoriesSuggestionsProvider, Suggestion} from "../autocompletion_utils/Common";
33
import * as _ from "lodash";
44
import {PluginManager} from "../../PluginManager";

src/shell/Command.ts renamed to src/shell/BuiltInCommands.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {EOL} from "os";
66
import {Session} from "./Session";
77
import {OrderedSet} from "../utils/OrderedSet";
88
import {parseAlias} from "./Aliases";
9+
import {stringLiteralValue} from "./Scanner";
910

1011
const executors: Dictionary<(i: Job, a: string[]) => void> = {
1112
cd: (job: Job, args: string[]): void => {
@@ -89,8 +90,12 @@ export function sourceFile(session: Session, fileName: string) {
8990

9091
content.split(EOL).forEach(line => {
9192
if (line.startsWith("export ")) {
92-
const [key, value] = line.split(" ")[1].split("=");
93-
session.environment.set(key, value);
93+
const [variableName, variableValueLiteral] = line.split(" ")[1].split("=");
94+
95+
const variableValue = stringLiteralValue(variableValueLiteral);
96+
if (variableValue) {
97+
session.environment.set(variableName, variableValue);
98+
}
9499
}
95100
});
96101
}

src/shell/CommandExecutor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Job} from "./Job";
2-
import {Command} from "./Command";
2+
import {Command} from "./BuiltInCommands";
33
import {PTY} from "../PTY";
44
import * as Path from "path";
55
import {resolveFile, isWindows, filterAsync, io} from "../utils/Common";

src/shell/Scanner.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,3 +285,25 @@ export function expandAliases(tokens: Token[], aliases: Aliases): Token[] {
285285
return tokens;
286286
}
287287
}
288+
289+
export function stringLiteralValue(literal: string): string | undefined {
290+
const tokens = scan(literal);
291+
292+
if (tokens.length !== 1) {
293+
return;
294+
}
295+
296+
const token = tokens[0];
297+
298+
if (token instanceof DoubleQuotedStringLiteral) {
299+
return token.value;
300+
}
301+
302+
if (token instanceof SingleQuotedStringLiteral) {
303+
return token.value;
304+
}
305+
306+
if (token instanceof Word) {
307+
return token.value;
308+
}
309+
}

0 commit comments

Comments
 (0)