Skip to content

Commit afb048f

Browse files
fix: handling escaped urls
1 parent e091d27 commit afb048f

File tree

4 files changed

+69
-11
lines changed

4 files changed

+69
-11
lines changed

src/plugins/postcss-url-parser.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import postcss from 'postcss';
22
import valueParser from 'postcss-value-parser';
33
import { urlToRequest } from 'loader-utils';
44

5+
import { unescape } from '../utils';
6+
57
const pluginName = 'postcss-url-parser';
68

79
const isUrlFunc = /url/i;
@@ -78,23 +80,20 @@ function getUrlsFromValue(value, result, filter, decl) {
7880
}
7981

8082
const splittedUrl = url.split(/(\?)?#/);
81-
let normalizedUrl = urlToRequest(decodeURIComponent(splittedUrl[0]));
83+
let [normalizedUrl] = splittedUrl;
8284
const [, singleQuery, hashValue] = splittedUrl;
8385
const hash =
8486
singleQuery || hashValue
8587
? `${singleQuery ? '?' : ''}${hashValue ? `#${hashValue}` : ''}`
8688
: '';
8789

88-
// Remove extra escaping requirements for `require`
89-
// See https://drafts.csswg.org/css-values-3/#urls
90-
if (!isStringNode && /\\["'() \t\n]/.test(normalizedUrl)) {
91-
normalizedUrl = normalizedUrl.replace(/\\(["'() \t\n])/g, '$1');
92-
}
93-
// https://drafts.csswg.org/css-values-4/#strings
94-
else if (isStringNode && /\\[\n]/.test(normalizedUrl)) {
90+
// See https://drafts.csswg.org/css-values-4/#strings
91+
if (isStringNode && /\\[\n]/.test(normalizedUrl)) {
9592
normalizedUrl = normalizedUrl.replace(/\\[\n]/g, '');
9693
}
9794

95+
normalizedUrl = urlToRequest(decodeURIComponent(unescape(normalizedUrl)));
96+
9897
urls.push({ node, url: normalizedUrl, hash, needQuotes });
9998
});
10099

src/utils.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ function getExportCode(
395395
}
396396

397397
export {
398+
unescape,
398399
getFilter,
399400
getModulesPlugins,
400401
normalizeSourceMap,

0 commit comments

Comments
 (0)