Skip to content

Commit c4402b1

Browse files
alan-agius4dgp1130
authored andcommitted
fix(@angular-devkit/build-angular): correctly handle parenthesis in url
PR #23691 introduced a regression that caused paranthesis in url not to be handled correctly. This change correct this behaviour and adds a test case to valid this. Closes #23773 (cherry picked from commit 147f8c3)
1 parent 1c06181 commit c4402b1

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

packages/angular_devkit/build_angular/src/builders/browser/specs/styles_spec.ts

+16
Original file line numberDiff line numberDiff line change
@@ -706,4 +706,20 @@ describe('Browser Builder styles', () => {
706706
const result = await browserBuild(architect, host, target, { styles: ['src/styles.css'] });
707707
expect(await result.files['styles.css']).toContain(svgData);
708708
});
709+
710+
it('works when Data URI has parenthesis', async () => {
711+
const svgData =
712+
'"data:image/svg+xml;charset=utf-8,<svg>' +
713+
`<mask id='clip'><g><circle mask='url(%23clip)' cx='11.5' cy='11.5' r='9.25'/><use xlink:href='#text' mask='url(#clip)'/></g>` +
714+
'</svg>"';
715+
716+
host.writeMultipleFiles({
717+
'src/styles.css': `
718+
div { background: url(${svgData}) }
719+
`,
720+
});
721+
722+
const result = await browserBuild(architect, host, target, { styles: ['src/styles.css'] });
723+
expect(await result.files['styles.css']).toContain(svgData);
724+
});
709725
});

packages/angular_devkit/build_angular/src/webpack/plugins/postcss-cli-resources.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ export default function (options?: PostcssCliResourcesOptions): Plugin {
155155
}
156156

157157
const value = decl.value;
158-
const urlRegex = /url(?:\(\s*['"]?)(.*?)(?:['"]?\s*\))/g;
158+
const urlRegex = /url(?:\(\s*(['"]?))(.*?)(?:\1\s*\))/g;
159159
const segments: string[] = [];
160160

161161
let match;
@@ -166,9 +166,8 @@ export default function (options?: PostcssCliResourcesOptions): Plugin {
166166
const inputFile = decl.source && decl.source.input.file;
167167
const context = (inputFile && path.dirname(inputFile)) || loader.context;
168168

169-
// eslint-disable-next-line no-cond-assign
170169
while ((match = urlRegex.exec(value))) {
171-
const originalUrl = match[1];
170+
const originalUrl = match[2];
172171
let processedUrl;
173172
try {
174173
processedUrl = await process(originalUrl, context, resourceCache);

0 commit comments

Comments
 (0)