diff --git a/packages/angular/cli/commands/config-impl.ts b/packages/angular/cli/commands/config-impl.ts index 06850ea83946..f69e5f024dc1 100644 --- a/packages/angular/cli/commands/config-impl.ts +++ b/packages/angular/cli/commands/config-impl.ts @@ -86,12 +86,12 @@ const validCliPaths = new Map 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(); @@ -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( diff --git a/tests/legacy-cli/e2e/tests/commands/config/config-get.ts b/tests/legacy-cli/e2e/tests/commands/config/config-get.ts index a5abd6ad6fed..4786838afefc 100644 --- a/tests/legacy-cli/e2e/tests/commands/config/config-get.ts +++ b/tests/legacy-cli/e2e/tests/commands/config/config-get.ts @@ -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)}".`); + } + }); }