Skip to content

Commit

Permalink
fix: do not crash on unescaped svg data uri (#1288)
Browse files Browse the repository at this point in the history
alexander-akait authored Apr 9, 2021

Verified

This commit was signed with the committer’s verified signature.
1 parent dcce860 commit 4f289c5
Showing 3 changed files with 55 additions and 9 deletions.
18 changes: 16 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -98,10 +98,24 @@ function normalizeUrl(url, isStringValue) {
}

if (matchNativeWin32Path.test(url)) {
return decodeURI(normalizedUrl);
try {
normalizedUrl = decodeURI(normalizedUrl);
} catch (error) {
// Ignore
}

return normalizedUrl;
}

normalizedUrl = unescape(normalizedUrl);

try {
normalizedUrl = decodeURI(normalizedUrl);
} catch (error) {
// Ignore
}

return decodeURI(unescape(normalizedUrl));
return normalizedUrl;
}

function requestify(url, rootContext) {
42 changes: 35 additions & 7 deletions test/__snapshots__/url-option.test.js.snap

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions test/fixtures/url/url.css
Original file line number Diff line number Diff line change
@@ -389,6 +389,10 @@ a {
background-image: image-set(url('./img.png', 'foo', './img.png', url('./img.png')) 1x, url("./img2x.png") 2x);
}

.button {
background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg"><rect width="100%" height="100%" style="stroke: rgb(223,224,225); stroke-width: 2px; fill: none; stroke-dasharray: 6px 3px" /></svg>');
}

/* We need to use `resourceQuery: /inline/` */
/* Hard to test on webpack v4 */
/*.qqq {*/

0 comments on commit 4f289c5

Please sign in to comment.