66"use strict" ;
77
88const specialChar = {
9- "\\r" : "\r" ,
10- "\\n" : "\n" ,
11- "\\t" : "\t" ,
12- "\\v" : String . fromCharCode ( 11 ) ,
13- "\\e" : String . fromCharCode ( 27 ) ,
14- "\\f" : String . fromCharCode ( 12 ) ,
15- "\\\\" : "\\" ,
16- "\\$" : "$" ,
17- '\\"' : '"' ,
18- "\\'" : "'"
9+ "\\" : "\\" ,
10+ $ : "$" ,
11+ n : "\n" ,
12+ r : "\r" ,
13+ t : "\t" ,
14+ f : String . fromCharCode ( 12 ) ,
15+ v : String . fromCharCode ( 11 ) ,
16+ e : String . fromCharCode ( 27 )
1917} ;
2018
2119module . exports = {
@@ -25,13 +23,24 @@ module.exports = {
2523 resolve_special_chars : function ( text , doubleQuote ) {
2624 if ( ! doubleQuote ) {
2725 // single quote fix
28- return text . replace ( / \\ [ ' \\ ] / g, function ( seq ) {
29- return specialChar [ seq ] ;
30- } ) ;
26+ return text . replace ( / \\ \\ / g, "\\" ) . replace ( / \\ ' / g, "'" ) ;
3127 }
32- return text . replace ( / \\ [ r n t v e f " ' \\ $ ] / g, function ( seq ) {
33- return specialChar [ seq ] ;
34- } ) ;
28+ return text
29+ . replace ( / \\ " / , '"' )
30+ . replace (
31+ / \\ ( [ \\ $ n r t f v e ] | [ x X ] [ 0 - 9 a - f A - F ] { 1 , 2 } | [ 0 - 7 ] { 1 , 3 } | u { ( [ 0 - 9 a - f A - F ] + ) } ) / g,
32+ ( $match , p1 , p2 ) => {
33+ if ( specialChar [ p1 ] ) {
34+ return specialChar [ p1 ] ;
35+ } else if ( "x" === p1 [ 0 ] || "X" === p1 [ 0 ] ) {
36+ return String . fromCodePoint ( parseInt ( p1 . substr ( 1 ) , 16 ) ) ;
37+ } else if ( "u" === p1 [ 0 ] ) {
38+ return String . fromCodePoint ( parseInt ( p2 , 16 ) ) ;
39+ } else {
40+ return String . fromCodePoint ( parseInt ( p1 , 8 ) ) ;
41+ }
42+ }
43+ ) ;
3544 } ,
3645 /**
3746 * ```ebnf
@@ -59,12 +68,13 @@ module.exports = {
5968 }
6069 const isDoubleQuote = text [ offset ] === '"' ;
6170 this . next ( ) ;
71+ const textValue = this . resolve_special_chars (
72+ text . substring ( offset + 1 , text . length - 1 ) ,
73+ isDoubleQuote
74+ ) ;
6275 value = value (
6376 isDoubleQuote ,
64- this . resolve_special_chars (
65- text . substring ( offset + 1 , text . length - 1 ) ,
66- isDoubleQuote
67- ) ,
77+ textValue ,
6878 offset === 1 , // unicode flag
6979 text
7080 ) ;
0 commit comments