Skip to content

Commit 757d8df

Browse files
Alan Agiusmgechev
Alan Agius
authored andcommitted
fix(@angular/cli): ng config doesn't parse positional array
Fixes #14516
1 parent c70cf99 commit 757d8df

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

packages/angular/cli/commands/config-impl.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@ const validCliPaths = new Map<string, ((arg: string) => JsonValue)>([
8686
* by the path. For example, a path of "a[3].foo.bar[2]" would give you a fragment array of
8787
* ["a", 3, "foo", "bar", 2].
8888
* @param path The JSON string to parse.
89-
* @returns {string[]} The fragments for the string.
89+
* @returns {(string|number)[]} The fragments for the string.
9090
* @private
9191
*/
92-
function parseJsonPath(path: string): string[] {
92+
function parseJsonPath(path: string): (string|number)[] {
9393
const fragments = (path || '').split(/\./g);
94-
const result: string[] = [];
94+
const result: (string|number)[] = [];
9595

9696
while (fragments.length > 0) {
9797
const fragment = fragments.shift();
@@ -106,12 +106,15 @@ function parseJsonPath(path: string): string[] {
106106

107107
result.push(match[1]);
108108
if (match[2]) {
109-
const indices = match[2].slice(1, -1).split('][');
109+
const indices = match[2]
110+
.slice(1, -1)
111+
.split('][')
112+
.map(x => /^\d$/.test(x) ? +x : x.replace(/\"|\'/g, ''));
110113
result.push(...indices);
111114
}
112115
}
113116

114-
return result.filter(fragment => !!fragment);
117+
return result.filter(fragment => fragment != null);
115118
}
116119

117120
function getValueFromPath<T extends JsonArray | JsonObject>(

tests/legacy-cli/e2e/tests/commands/config/config-get.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,17 @@ export default function() {
1919
throw new Error(`Expected "true", received "${JSON.stringify(stdout)}".`);
2020
}
2121
})
22-
.then(() => ng('config', 'schematics.@schematics/angular.component.inlineStyle', 'false'));
22+
.then(() => ng('config', 'schematics.@schematics/angular.component.inlineStyle', 'false'))
23+
.then(() => ng('config', `projects.test-project.architect.build.options.assets[0]`))
24+
.then(({ stdout }) => {
25+
if (!stdout.includes('src/favicon.ico')) {
26+
throw new Error(`Expected "src/favicon.ico", received "${JSON.stringify(stdout)}".`);
27+
}
28+
})
29+
.then(() => ng('config', `projects["test-project"].architect.build.options.assets[0]`))
30+
.then(({ stdout }) => {
31+
if (!stdout.includes('src/favicon.ico')) {
32+
throw new Error(`Expected "src/favicon.ico", received "${JSON.stringify(stdout)}".`);
33+
}
34+
});
2335
}

0 commit comments

Comments
 (0)