Skip to content

Commit

Permalink
Fixes clean-css#763 - data URI SVG and quoting.
Browse files Browse the repository at this point in the history
Quotes inside data URI SVG can be unescaped and we should handle
such cases correctly by leaving quoting in place.
  • Loading branch information
jakubpawlowicz authored and silverwind committed Sep 25, 2016
1 parent dcb01d0 commit f595de6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions History.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
==================

* Fixed issue [#751](https:/jakubpawlowicz/clean-css/issues/751) - stringifying CSS variables.
* Fixed issue [#763](https:/jakubpawlowicz/clean-css/issues/763) - data URI SVG and quoting.

[3.4.13 / 2016-05-23](https:/jakubpawlowicz/clean-css/compare/v3.4.12...v3.4.13)
==================
Expand Down
3 changes: 3 additions & 0 deletions lib/text/urls-processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ function normalize(url, keepUrlQuotes) {
.replace(/^url\((['"])? /, 'url($1')
.replace(/ (['"])?\)$/, '$1)');

if (/url\(".*'.*"\)/.test(url) || /url\('.*".*'\)/.test(url))
return url;

if (!keepUrlQuotes && !/^['"].+['"]$/.test(url) && !/url\(.*[\s\(\)].*\)/.test(url) && !/url\(['"]data:[^;]+;charset/.test(url))
url = url.replace(/["']/g, '');

Expand Down
8 changes: 8 additions & 0 deletions test/integration-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1381,6 +1381,14 @@ vows.describe('integration tests')
'quotes SVG data URI if with parentheses': [
'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}',
'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}'
],
'do not unquote double quoted URI with unescaped single quotes inside': [
'a{background:url("data:image/svg+xml,%3csvg%20xmlns%3d\'http://www.w3.org/2000/svg\'/%3e")}',
'a{background:url("data:image/svg+xml,%3csvg%20xmlns%3d\'http://www.w3.org/2000/svg\'/%3e")}'
],
'do not unquote single quoted URI with unescaped double quotes inside': [
'a{background:url(\'data:image/svg+xml,%3csvg%20xmlns%3d"http://www.w3.org/2000/svg"/%3e\')}',
'a{background:url(\'data:image/svg+xml,%3csvg%20xmlns%3d"http://www.w3.org/2000/svg"/%3e\')}'
]
}, { root: process.cwd(), relativeTo: process.cwd() })
)
Expand Down

0 comments on commit f595de6

Please sign in to comment.