1- const path = require ( 'path' )
2- const { interpolateName } = require ( 'loader-utils' )
1+ const path = require ( 'path' ) ;
2+ const cssesc = require ( 'cssesc' ) ;
3+ const { interpolateName } = require ( 'loader-utils' ) ;
34
45const pluginOptions = {
56 includePaths : [ ] ,
67 localIdentName : '[local]-[hash:base64:6]'
7- }
8+ } ;
89
910const regex = {
1011 module : / \$ ( s t y l e ) ? \. ( : ? [ \w \d - ] * ) / gm,
@@ -17,27 +18,35 @@ const regex = {
1718let moduleClasses = { } ;
1819
1920function generateName ( resourcePath , styles , className ) {
20- const filePath = resourcePath
21- const fileName = path . basename ( filePath )
21+ const filePath = resourcePath ;
22+ const fileName = path . basename ( filePath ) ;
2223 const localName = pluginOptions . localIdentName . length
2324 ? pluginOptions . localIdentName . replace ( / \[ l o c a l \] / gi, ( ) => className )
24- : className
25+ : className ;
2526
26- const content = `${ styles } -${ filePath } -${ fileName } -${ className } `
27+ const content = `${ styles } -${ filePath } -${ fileName } -${ className } ` ;
2728
28- let interpolatedName = interpolateName ( { resourcePath } , localName , { content } )
29+ let interpolatedName = cssesc (
30+ interpolateName ( { resourcePath } , localName , { content } )
31+ . replace ( / \. / g, '-' )
32+ ) ;
33+
34+ // replace unwanted characters from [path]
35+ if ( / [ < > : " / \\ | ? * ] / g. test ( interpolatedName ) ) {
36+ interpolatedName = interpolatedName . replace ( regex . pathUnallowed , '_' ) ;
37+ }
2938
3039 // prevent class error when the generated classname starts from a non word charater
3140 if ( / ^ (? ! [ a - z A - Z _ ] ) / . test ( interpolatedName ) ) {
32- interpolatedName = `_${ interpolatedName } `
41+ interpolatedName = `_${ interpolatedName } ` ;
3342 }
3443
3544 // prevent svelte "Unused CSS selector" warning when the generated classname ends by `-`
3645 if ( interpolatedName . slice ( - 1 ) === '-' ) {
37- interpolatedName = interpolatedName . slice ( 0 , - 1 )
46+ interpolatedName = interpolatedName . slice ( 0 , - 1 ) ;
3847 }
3948
40- return interpolatedName
49+ return interpolatedName ;
4150}
4251
4352const markup = async ( { content, filename } ) => {
0 commit comments