Skip to content

Commit

Permalink
fix(@angular/cli): ng config doesn't parse positional array
Browse files Browse the repository at this point in the history
Fixes #14516
  • Loading branch information
Alan Agius authored and mgechev committed May 28, 2019
1 parent c70cf99 commit 757d8df
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
13 changes: 8 additions & 5 deletions packages/angular/cli/commands/config-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ const validCliPaths = new Map<string, ((arg: string) => JsonValue)>([
* by the path. For example, a path of "a[3].foo.bar[2]" would give you a fragment array of
* ["a", 3, "foo", "bar", 2].
* @param path The JSON string to parse.
* @returns {string[]} The fragments for the string.
* @returns {(string|number)[]} The fragments for the string.
* @private
*/
function parseJsonPath(path: string): string[] {
function parseJsonPath(path: string): (string|number)[] {
const fragments = (path || '').split(/\./g);
const result: string[] = [];
const result: (string|number)[] = [];

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

result.push(match[1]);
if (match[2]) {
const indices = match[2].slice(1, -1).split('][');
const indices = match[2]
.slice(1, -1)
.split('][')
.map(x => /^\d$/.test(x) ? +x : x.replace(/\"|\'/g, ''));
result.push(...indices);
}
}

return result.filter(fragment => !!fragment);
return result.filter(fragment => fragment != null);
}

function getValueFromPath<T extends JsonArray | JsonObject>(
Expand Down
14 changes: 13 additions & 1 deletion tests/legacy-cli/e2e/tests/commands/config/config-get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,17 @@ export default function() {
throw new Error(`Expected "true", received "${JSON.stringify(stdout)}".`);
}
})
.then(() => ng('config', 'schematics.@schematics/angular.component.inlineStyle', 'false'));
.then(() => ng('config', 'schematics.@schematics/angular.component.inlineStyle', 'false'))
.then(() => ng('config', `projects.test-project.architect.build.options.assets[0]`))
.then(({ stdout }) => {
if (!stdout.includes('src/favicon.ico')) {
throw new Error(`Expected "src/favicon.ico", received "${JSON.stringify(stdout)}".`);
}
})
.then(() => ng('config', `projects["test-project"].architect.build.options.assets[0]`))
.then(({ stdout }) => {
if (!stdout.includes('src/favicon.ico')) {
throw new Error(`Expected "src/favicon.ico", received "${JSON.stringify(stdout)}".`);
}
});
}

0 comments on commit 757d8df

Please sign in to comment.