Skip to content

Commit 0fe58a3

Browse files
island205jakubpawlowicz
authored andcommitted
fix #701 properties.urlQuotes doesn't work
Prevent SourceReader to remove all quote in url() add test case
1 parent 3602377 commit 0fe58a3

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

lib/urls/rewrite.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,16 @@ function quoteFor(url) {
9191
}
9292

9393
function rewriteUrls(data, options, context) {
94-
return reduceUrls(data, context, function (url, tempData) {
95-
url = url.replace(/^(url\()?\s*['"]?|['"]?\s*\)?$/g, '');
96-
tempData.push('url(' + quoteFor(url) + rebase(url, options) + quoteFor(url) + ')');
94+
return reduceUrls(data, context, function (originUrl, tempData) {
95+
var url = originUrl.replace(/^(url\()?\s*['"]?|['"]?\s*\)?$/g, '');
96+
var match = originUrl.match(/^(url\()?\s*(['"]).*?(['"])\s*\)?$/);
97+
var quote;
98+
if (!!options.urlQuotes && match && match[2] === match[3]) {
99+
quote = match[2];
100+
} else {
101+
quote = quoteFor(url);
102+
}
103+
tempData.push('url(' + quote + rebase(url, options) + quote + ')');
97104
});
98105
}
99106

lib/utils/source-reader.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ function fromHash(self) {
7474
imports: true,
7575
rebase: self.outerContext.options.rebase,
7676
fromBase: absoluteSourcePath,
77-
toBase: isRemote ? absoluteSourcePath : toBase
77+
toBase: isRemote ? absoluteSourcePath : toBase,
78+
urlQuotes: self.outerContext.options.compatibility.properties.urlQuotes
7879
};
7980
styles = rewriteUrls(styles, rewriteOptions, self.outerContext);
8081

test/integration-test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,6 +1374,18 @@ vows.describe('integration tests')
13741374
'keeps quotes as they are': [
13751375
'div{background:url("test.png")}',
13761376
'div{background:url("test.png")}'
1377+
],
1378+
'keeps quotes as they are when minify hash data': [
1379+
{'temp/file.css': {
1380+
styles: 'div{background:url("test.png")}'
1381+
}},
1382+
'div{background:url("temp/test.png")}'
1383+
],
1384+
'no quotes added when minify hash data': [
1385+
{'temp/file.css': {
1386+
styles: 'div{background:url(test.png)}'
1387+
}},
1388+
'div{background:url(temp/test.png)}'
13771389
]
13781390
}, { compatibility: { properties: { urlQuotes: true } } })
13791391
)

0 commit comments

Comments
 (0)