File tree 4 files changed +27
-21
lines changed
4 files changed +27
-21
lines changed Original file line number Diff line number Diff line change @@ -23,9 +23,15 @@ function endSpacingMatch(match) {
23
23
}
24
24
25
25
function unescapeString ( content ) {
26
- return content . replace ( / \\ ( [ a - f A - F 0 - 9 ] { 4 } | .) / g, function ( escaped ) {
26
+ return content . replace ( / \\ ( [ a - f A - F 0 - 9 ] { 2 , 5 } | .) / g, function ( escaped ) {
27
27
if ( escaped . length > 2 ) {
28
- return String . fromCharCode ( parseInt ( escaped . substr ( 1 ) , 16 ) ) ;
28
+ var C = parseInt ( escaped . substr ( 1 ) , 16 ) ;
29
+ if ( C < 0x10000 ) {
30
+ return String . fromCharCode ( C ) ;
31
+ } else {
32
+ return String . fromCharCode ( Math . floor ( ( C - 0x10000 ) / 0x400 ) + 0xD800 ) +
33
+ String . fromCharCode ( ( C - 0x10000 ) % 0x400 + 0xDC00 ) ;
34
+ }
29
35
} else {
30
36
return escaped . substr ( 1 ) ;
31
37
}
Original file line number Diff line number Diff line change 1
1
"use strict" ;
2
2
3
+ var cssesc = require ( "cssesc" ) ;
4
+
3
5
var stringify ;
4
6
5
7
function escape ( str , stringType ) {
6
- return str . replace ( / [ " ' \\ \x80 - \uFFFF ] / g, function ( match ) {
7
- switch ( match ) {
8
- case "\"" :
9
- if ( stringType === "\"" ) {
10
- return "\\\"" ;
11
- }
12
- return match ;
13
- case "'" :
14
- if ( stringType === "'" ) {
15
- return "\\'" ;
16
- }
17
- return match ;
18
- case "\\" :
19
- return "\\\\" ;
20
- default :
21
- return "\\" + ( 0x10000 + match . charCodeAt ( 0 ) ) . toString ( 16 ) . substr ( 1 ) ;
22
- }
8
+ return cssesc ( str , {
9
+ quotes : stringType === "\"" ? "double" : "single"
23
10
} ) ;
24
11
}
25
12
Original file line number Diff line number Diff line change 31
31
},
32
32
"homepage" : " https://github.com/css-modules/css-selector-tokenizer" ,
33
33
"dependencies" : {
34
+ "cssesc" : " ^0.1.0" ,
34
35
"fastparse" : " ^1.1.1"
35
36
},
36
37
"devDependencies" : {
Original file line number Diff line number Diff line change @@ -125,17 +125,29 @@ module.exports = {
125
125
}
126
126
] ,
127
127
"escaped unicode" : [
128
- "'\\f0e3 \\\\\\'\"'" ,
128
+ "'\\F0E3 \\\\\\'\"'" ,
129
129
singleValue ( [
130
130
{ type : "string" , stringType : "'" , value : "\uf0e3\\'\"" }
131
131
] )
132
132
] ,
133
133
"escaped unicode 2" : [
134
- "\"\\f0e3 \\\\'\\\"\"" ,
134
+ "\"\\F0E3 \\\\'\\\"\"" ,
135
135
singleValue ( [
136
136
{ type : "string" , stringType : "\"" , value : "\uf0e3\\'\"" }
137
137
] )
138
138
] ,
139
+ "escaped unicode 3 (short)" : [
140
+ "\"\\10\"" ,
141
+ singleValue ( [
142
+ { type : "string" , stringType : "\"" , value : "\u0010" }
143
+ ] )
144
+ ] ,
145
+ "escaped unicode 4 (surrogate pair)" : [
146
+ "\"\\1F50E\"" ,
147
+ singleValue ( [
148
+ { type : "string" , stringType : "\"" , value : "\ud83d\udd0e" }
149
+ ] )
150
+ ] ,
139
151
"nested-item-with append" : [
140
152
"linear-gradient(45deg) 25%" ,
141
153
singleValue ( [
You can’t perform that action at this time.
0 commit comments