Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(@angular-devkit/build-angular): correctly handle parenthesis in url #23774

Merged
merged 1 commit into from
Aug 22, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -706,4 +706,20 @@ describe('Browser Builder styles', () => {
const result = await browserBuild(architect, host, target, { styles: ['src/styles.css'] });
expect(await result.files['styles.css']).toContain(svgData);
});

it('works when Data URI has parenthesis', async () => {
const svgData =
'"data:image/svg+xml;charset=utf-8,<svg>' +
`<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>` +
'</svg>"';

host.writeMultipleFiles({
'src/styles.css': `
div { background: url(${svgData}) }
`,
});

const result = await browserBuild(architect, host, target, { styles: ['src/styles.css'] });
expect(await result.files['styles.css']).toContain(svgData);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export default function (options?: PostcssCliResourcesOptions): Plugin {
}

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

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

// eslint-disable-next-line no-cond-assign
while ((match = urlRegex.exec(value))) {
const originalUrl = match[1];
const originalUrl = match[2];
let processedUrl;
try {
processedUrl = await process(originalUrl, context, resourceCache);
Expand Down