Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)}".`);
}
});
}