@@ -259,8 +259,10 @@ function normalizePath(file) {
259
259
return path . sep === "\\" ? file . replace ( / \\ / g, "/" ) : file ;
260
260
}
261
261
262
+ const reversedChartMapper = { } ;
263
+
262
264
// eslint-disable-next-line no-control-regex
263
- const filenameReservedRegex = / [ < > : " / \\ | ? * \s ] / g;
265
+ const filenameReservedRegex = / ( [ < > : " / \\ | ? * \s ] ) / g;
264
266
// eslint-disable-next-line no-control-regex
265
267
const reControlChars = / [ \u0000 - \u001f \u0080 - \u009f ] / g;
266
268
@@ -270,7 +272,21 @@ function escapeLocalIdent(localident) {
270
272
localident
271
273
// For `[hash]` placeholder
272
274
. replace ( / ^ ( ( - ? [ 0 - 9 ] ) | - - ) / , "_$1" )
273
- . replace ( filenameReservedRegex , "-" )
275
+ . replace ( filenameReservedRegex , ( _ , $1 ) => {
276
+ // normalize Windows path `\` as unix `/` for constancy
277
+ const char = $1 === "\\" && path . sep === "\\" ? "/" : $1 ;
278
+
279
+ if ( reversedChartMapper [ char ] ) {
280
+ return reversedChartMapper [ char ] ;
281
+ }
282
+
283
+ const hex = char . charCodeAt ( 0 ) . toString ( 16 ) . toUpperCase ( ) ;
284
+ const escaped = `\\C${ hex } ` ;
285
+
286
+ reversedChartMapper [ char ] = escaped ;
287
+
288
+ return escaped ;
289
+ } )
274
290
. replace ( reControlChars , "-" )
275
291
. replace ( / \. / g, "-" ) ,
276
292
) ;
0 commit comments