Skip to content

Commit 07ea718

Browse files
committed
Match parens recursively on URLs to not fix embeded calls
1 parent c1d1e48 commit 07ea718

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

fixUrls.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ module.exports = function (css) {
2929
var currentDir = baseUrl + location.pathname.replace(/\/[^\/]*$/, "/");
3030

3131
// convert each url(...)
32-
var fixedCss = css.replace(/url *\( *(.+?) *\)/g, function(fullMatch, origUrl) {
32+
var fixedCss = css.replace(/url\(((?:[^)(]+|\((?:[^)(]+|\([^)(]*\))*\))*)\)/g, function(fullMatch, origUrl) {
3333
// strip quotes (if they exist)
34+
3435
var unquotedOrigUrl = origUrl
3536
.replace(/^"(.*)"$/, function(o, $1){ return $1; })
3637
.replace(/^'(.*)'$/, function(o, $1){ return $1; });

test/fixUrlsTest.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,12 @@ describe("fix urls tests", function() {
180180
"http://x.y.z"
181181
);
182182
});
183+
184+
it("Doesn't break inline SVG", function() {
185+
const svg = "url('data:image/svg+xml;charset=utf-8,<svg><feFlood flood-color=\"rgba(0,0,0,0.5)\" /></svg>')";
186+
187+
assertUrl(
188+
"body: { background: " + svg + " }"
189+
);
190+
});
183191
});

0 commit comments

Comments
 (0)