Skip to content

Commit

Permalink
fix(material/schematics): don't replace variables contained within th…
Browse files Browse the repository at this point in the history
…e names of other variables in theming API migration (#24021)

Fixes that the theming API migration would replace the `$swift-ease-in` inside a variable like `$swift-ease-in-duration`, because the regex would partially match the name.

Fixes #24013.
  • Loading branch information
crisbeto authored Dec 14, 2021
1 parent 470abdf commit 7468588
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ function replaceRemovedVariables(content: string, variables: Record<string, stri
Object.keys(variables).forEach(variableName => {
// Note that the pattern uses a negative lookahead to exclude
// variable assignments, because they can't be migrated.
const regex = new RegExp(`\\$${escapeRegExp(variableName)}(?!\\s+:|:)`, 'g');
const regex = new RegExp(`\\$${escapeRegExp(variableName)}(?!\\s+:|[-_a-zA-Z0-9:])`, 'g');
content = content.replace(regex, variables[variableName]);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,17 @@ describe('v12 theming API migration', () => {
]);
});

it('should not replace removed variables whose name overlaps with other variables', async () => {
writeLines(THEME_PATH, [
`@import '@angular/material/theming';`,
`$swift-ease-in-duration: 300ms !default`,
]);

await runMigration();

expect(splitFile(THEME_PATH)).toEqual([`$swift-ease-in-duration: 300ms !default`]);
});

it('should not replace assignments to removed variables', async () => {
writeLines(THEME_PATH, [
`@import '@angular/material/theming';`,
Expand Down

0 comments on commit 7468588

Please sign in to comment.