Skip to content

Commit

Permalink
Merge pull request #1043 from cssnano/fix-svg-warnings
Browse files Browse the repository at this point in the history
fix(postcss-svgo): fix processing declaration mixing svg and non svg
  • Loading branch information
ludofischer committed Apr 9, 2021
2 parents 747f16c + 7ae1cf7 commit 0e2c3bf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
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"),
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)) {
return;
}
let decodedUri;

try {
Expand Down

0 comments on commit 0e2c3bf

Please sign in to comment.