@@ -2,6 +2,8 @@ import postcss from 'postcss';
2
2
import valueParser from 'postcss-value-parser' ;
3
3
import { urlToRequest } from 'loader-utils' ;
4
4
5
+ import { unescape } from '../utils' ;
6
+
5
7
const pluginName = 'postcss-url-parser' ;
6
8
7
9
const isUrlFunc = / u r l / i;
@@ -78,23 +80,20 @@ function getUrlsFromValue(value, result, filter, decl) {
78
80
}
79
81
80
82
const splittedUrl = url . split ( / ( \? ) ? # / ) ;
81
- let normalizedUrl = urlToRequest ( decodeURIComponent ( splittedUrl [ 0 ] ) ) ;
83
+ let [ normalizedUrl ] = splittedUrl ;
82
84
const [ , singleQuery , hashValue ] = splittedUrl ;
83
85
const hash =
84
86
singleQuery || hashValue
85
87
? `${ singleQuery ? '?' : '' } ${ hashValue ? `#${ hashValue } ` : '' } `
86
88
: '' ;
87
89
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 ) ) {
95
92
normalizedUrl = normalizedUrl . replace ( / \\ [ \n ] / g, '' ) ;
96
93
}
97
94
95
+ normalizedUrl = urlToRequest ( decodeURIComponent ( unescape ( normalizedUrl ) ) ) ;
96
+
98
97
urls . push ( { node, url : normalizedUrl , hash, needQuotes } ) ;
99
98
} ) ;
100
99
0 commit comments