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(postcss-svgo): fix processing declaration mixing svg and non svg #1043

Merged
merged 1 commit into from Apr 9, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/postcss-svgo/src/__tests__/index.js
Expand Up @@ -198,6 +198,15 @@ test('should warn on SVG containing unclosed tags', async () => {
expect(result.messages[0].type).toBe('warning');
});

test('should only warn with svg data uri', async () => {
const css = `@font-face {
src: url("https://example/dfds.woff2") format("woff2"),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something weird here. The test fails with an error inside postcss-value-parser if I try a relative URL (url(example/dfds.woff2)). I assume url() handling has been tested elsewhere?

url('data:image/svg+xml;charset=utf-8,<svg></svg>') format("svg");
}`;
const result = await postcss(plugin()).process(css, { from: undefined });
expect(result.messages.length).toBe(0);
});

test(
'should pass through links to svg files',
passthroughCSS('h1{background:url(unicorn.svg)}')
Expand Down
3 changes: 3 additions & 0 deletions packages/postcss-svgo/src/index.js
Expand Up @@ -28,6 +28,9 @@ function minify(decl, opts, postcssResult) {
svg = Buffer.from(base64String, 'base64').toString('utf8');
isBase64 = true;
} else {
if (!dataURI.test(value)) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the value is not Base64-encoded, the code did not check whether the value was an SVG.

return;
}
let decodedUri;

try {
Expand Down