File tree Expand file tree Collapse file tree 4 files changed +27
-21
lines changed Expand file tree Collapse file tree 4 files changed +27
-21
lines changed Original file line number Diff line number Diff line change @@ -23,9 +23,15 @@ function endSpacingMatch(match) {
2323}
2424
2525function 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 ) {
2727 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+ }
2935 } else {
3036 return escaped . substr ( 1 ) ;
3137 }
Original file line number Diff line number Diff line change 11"use strict" ;
22
3+ var cssesc = require ( "cssesc" ) ;
4+
35var stringify ;
46
57function 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"
2310 } ) ;
2411}
2512
Original file line number Diff line number Diff line change 3131 },
3232 "homepage" : " https://github.com/css-modules/css-selector-tokenizer" ,
3333 "dependencies" : {
34+ "cssesc" : " ^0.1.0" ,
3435 "fastparse" : " ^1.1.1"
3536 },
3637 "devDependencies" : {
Original file line number Diff line number Diff line change @@ -125,17 +125,29 @@ module.exports = {
125125 }
126126 ] ,
127127 "escaped unicode" : [
128- "'\\f0e3 \\\\\\'\"'" ,
128+ "'\\F0E3 \\\\\\'\"'" ,
129129 singleValue ( [
130130 { type : "string" , stringType : "'" , value : "\uf0e3\\'\"" }
131131 ] )
132132 ] ,
133133 "escaped unicode 2" : [
134- "\"\\f0e3 \\\\'\\\"\"" ,
134+ "\"\\F0E3 \\\\'\\\"\"" ,
135135 singleValue ( [
136136 { type : "string" , stringType : "\"" , value : "\uf0e3\\'\"" }
137137 ] )
138138 ] ,
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+ ] ,
139151 "nested-item-with append" : [
140152 "linear-gradient(45deg) 25%" ,
141153 singleValue ( [
You can’t perform that action at this time.
0 commit comments