Skip to content

Commit 4311ff4

Browse files
Fixes #692 - edge case in URL quoting.
When a SVG contains brackets it should always be quoted.
1 parent f9aeff2 commit 4311ff4

File tree

5 files changed

+18
-6
lines changed

5 files changed

+18
-6
lines changed

History.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[3.4.7 / 2015-xx-xx](https://github.com/jakubpawlowicz/clean-css/compare/v3.4.6...3.4)
22
==================
33

4+
* Fixed issue [#692](https://github.com/jakubpawlowicz/clean-css/issues/692) - edge case in URL quoting.
45
* Fixed issue [#695](https://github.com/jakubpawlowicz/clean-css/issues/695) - shorthand overriding edge case.
56
* Fixed issue [#699](https://github.com/jakubpawlowicz/clean-css/issues/699) - IE9 transparent hack.
67
* Fixed issue [#701](https://github.com/jakubpawlowicz/clean-css/issues/701) - `url` quoting with hash arguments.

lib/urls/rewrite.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ function quoteFor(url) {
8484
return '"';
8585
else if (url.indexOf('"') > -1)
8686
return '\'';
87-
else if (/\s/.test(url))
87+
else if (/\s/.test(url) || /[\(\)]/.test(url))
8888
return '\'';
8989
else
9090
return '';

test/binary-test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,14 @@ vows.describe('./bin/cleancss')
272272
})
273273
}
274274
})
275+
.addBatch({
276+
'import rebasing': binaryContext('test/fixtures/partials/quoted-svg.css', {
277+
'should keep quoting intact': function (error, stdout) {
278+
assert.include(stdout, 'div{background:url(\'data:image');
279+
assert.include(stdout, 'svg%3E\')}');
280+
}
281+
})
282+
})
275283
.addBatch({
276284
'complex import and url rebasing': {
277285
'absolute': binaryContext('-r ./test/fixtures/129-assets ./test/fixtures/129-assets/assets/ui.css', {

test/fixtures/partials/quoted-svg.css

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/integration-test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,13 +1359,13 @@ vows.describe('integration tests')
13591359
'@font-face{src:url("/Helvetica Neue.eot")}',
13601360
'@font-face{src:url(\'/Helvetica Neue.eot\')}'
13611361
],
1362-
'keep SVG data URI unchanged for background-uri': [
1363-
'div{background-image:url(data:image/svg+xml,%3Csvg%20viewBox%3D%220%200%2018%2018%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2214%22%20height%3D%2214%22%20transform%3D%22translate(2%202)%22%2F%3E%3C%2Fsvg%3E)}',
1364-
'div{background-image:url(data:image/svg+xml,%3Csvg%20viewBox%3D%220%200%2018%2018%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2214%22%20height%3D%2214%22%20transform%3D%22translate(2%202)%22%2F%3E%3C%2Fsvg%3E)}'
1362+
'keep SVG data URI unchanged': [
1363+
'div{background:url(data:image/svg+xml,%3Csvg%20viewBox%3D%220%200%2018%2018%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2214%22%20height%3D%2214%22%2Fsvg%3E)}',
1364+
'div{background:url(data:image/svg+xml,%3Csvg%20viewBox%3D%220%200%2018%2018%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2214%22%20height%3D%2214%22%2Fsvg%3E)}'
13651365
],
1366-
'keep SVG data URI unchanged1 for background': [
1366+
'quotes SVG data URI if with parentheses': [
13671367
'div{background:url(data:image/svg+xml,%3Csvg%20viewBox%3D%220%200%2018%2018%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2214%22%20height%3D%2214%22%20transform%3D%22translate(2%202)%22%2F%3E%3C%2Fsvg%3E) bottom left}',
1368-
'div{background:url(data:image/svg+xml,%3Csvg%20viewBox%3D%220%200%2018%2018%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2214%22%20height%3D%2214%22%20transform%3D%22translate(2%202)%22%2F%3E%3C%2Fsvg%3E) bottom left}'
1368+
'div{background:url(\'data:image/svg+xml,%3Csvg%20viewBox%3D%220%200%2018%2018%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2214%22%20height%3D%2214%22%20transform%3D%22translate(2%202)%22%2F%3E%3C%2Fsvg%3E\') bottom left}'
13691369
]
13701370
}, { root: process.cwd(), relativeTo: process.cwd() })
13711371
)

0 commit comments

Comments
 (0)