Skip to content

Commit 0629a2c

Browse files
crisbetoamysorto
authored andcommitted
fix(material/schematics): don't replace variables contained within the 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. (cherry picked from commit 7468588)
1 parent 6ce89aa commit 0629a2c

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/material/schematics/ng-update/migrations/theming-api-v12/migration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ function replaceRemovedVariables(content: string, variables: Record<string, stri
397397
Object.keys(variables).forEach(variableName => {
398398
// Note that the pattern uses a negative lookahead to exclude
399399
// variable assignments, because they can't be migrated.
400-
const regex = new RegExp(`\\$${escapeRegExp(variableName)}(?!\\s+:|:)`, 'g');
400+
const regex = new RegExp(`\\$${escapeRegExp(variableName)}(?!\\s+:|[-_a-zA-Z0-9:])`, 'g');
401401
content = content.replace(regex, variables[variableName]);
402402
});
403403

src/material/schematics/ng-update/test-cases/v12/misc/theming-api-v12.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,17 @@ describe('v12 theming API migration', () => {
591591
]);
592592
});
593593

594+
it('should not replace removed variables whose name overlaps with other variables', async () => {
595+
writeLines(THEME_PATH, [
596+
`@import '@angular/material/theming';`,
597+
`$swift-ease-in-duration: 300ms !default`,
598+
]);
599+
600+
await runMigration();
601+
602+
expect(splitFile(THEME_PATH)).toEqual([`$swift-ease-in-duration: 300ms !default`]);
603+
});
604+
594605
it('should not replace assignments to removed variables', async () => {
595606
writeLines(THEME_PATH, [
596607
`@import '@angular/material/theming';`,

0 commit comments

Comments
 (0)