@@ -7,6 +7,7 @@ import path from 'path';
77import cc from 'camelcase' ;
88import loaderUtils from 'loader-utils' ;
99import normalizePath from 'normalize-path' ;
10+ import cssesc from 'cssesc' ;
1011
1112/* eslint-disable line-comment-position */
1213
@@ -79,16 +80,15 @@ function getLocalIdent(loaderContext, localIdentName, localName, options) {
7980 // eslint-disable-next-line no-param-reassign
8081 options . content = `${ options . hashPrefix + request } +${ unescape ( localName ) } ` ;
8182
82- // eslint-disable-next-line no-param-reassign
83- localIdentName = localIdentName . replace ( / \[ l o c a l \] / gi, localName ) ;
84-
85- const hash = loaderUtils . interpolateName (
86- loaderContext ,
87- localIdentName ,
88- options
89- ) ;
90-
91- return normalizeIdentifier ( hash ) ;
83+ // Using `[path]` placeholder outputs `/` we need escape their
84+ // Also directories can contains invalid characters for css we need escape their too
85+ return cssesc (
86+ loaderUtils
87+ . interpolateName ( loaderContext , localIdentName , options )
88+ // For `[hash]` placeholder
89+ . replace ( / ^ ( ( - ? [ 0 - 9 ] ) | - - ) / , '_$1' ) ,
90+ { isIdentifier : true }
91+ ) . replace ( / \\ \[ l o c a l \\ \] / gi, localName ) ;
9292}
9393
9494function getFilter ( filter , resourcePath , defaultFilter = null ) {
@@ -105,52 +105,6 @@ function getFilter(filter, resourcePath, defaultFilter = null) {
105105 } ;
106106}
107107
108- function normalizeIdentifier ( value ) {
109- const escapedSymbols = [
110- '~' ,
111- '!' ,
112- '@' ,
113- '#' ,
114- '$' ,
115- '%' ,
116- '&' ,
117- '^' ,
118- '*' ,
119- '(' ,
120- ')' ,
121- '{' ,
122- '}' ,
123- '[' ,
124- ']' ,
125- '`' ,
126- '/' ,
127- '=' ,
128- '?' ,
129- '+' ,
130- '\\' ,
131- '|' ,
132- '-' ,
133- '_' ,
134- ':' ,
135- ';' ,
136- "'" ,
137- '"' ,
138- ',' ,
139- '<' ,
140- '.' ,
141- '>' ,
142- ] ;
143-
144- const identifiersRegExp = new RegExp (
145- `[^a-zA-Z0-9${ escapedSymbols . join ( '\\' ) } \\-_\u00A0-\uFFFF]` ,
146- 'g'
147- ) ;
148-
149- return value
150- . replace ( identifiersRegExp , '-' )
151- . replace ( / ^ ( ( - ? [ 0 - 9 ] ) | - - ) / , '_$1' ) ;
152- }
153-
154108export {
155109 getImportPrefix ,
156110 getLocalIdent ,
0 commit comments