@@ -7,6 +7,7 @@ import path from 'path';
7
7
import cc from 'camelcase' ;
8
8
import loaderUtils from 'loader-utils' ;
9
9
import normalizePath from 'normalize-path' ;
10
+ import cssesc from 'cssesc' ;
10
11
11
12
/* eslint-disable line-comment-position */
12
13
@@ -79,16 +80,15 @@ function getLocalIdent(loaderContext, localIdentName, localName, options) {
79
80
// eslint-disable-next-line no-param-reassign
80
81
options . content = `${ options . hashPrefix + request } +${ unescape ( localName ) } ` ;
81
82
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 ) ;
92
92
}
93
93
94
94
function getFilter ( filter , resourcePath , defaultFilter = null ) {
@@ -105,52 +105,6 @@ function getFilter(filter, resourcePath, defaultFilter = null) {
105
105
} ;
106
106
}
107
107
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
-
154
108
export {
155
109
getImportPrefix ,
156
110
getLocalIdent ,
0 commit comments