File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -461,11 +461,21 @@ function foldLine(line, width) {
461
461
// Escapes a double-quoted string.
462
462
function escapeString ( string ) {
463
463
var result = '' ;
464
- var char ;
464
+ var char , nextChar ;
465
465
var escapeSeq ;
466
466
467
467
for ( var i = 0 ; i < string . length ; i ++ ) {
468
468
char = string . charCodeAt ( i ) ;
469
+ // Check for surrogate pairs.
470
+ if ( char >= 0xD800 && char <= 0xDBFF /* high surrogate */ ) {
471
+ nextChar = string . charCodeAt ( i + 1 ) ;
472
+ if ( nextChar >= 0xDC00 && nextChar <= 0xDFFF /* low surrogate */ ) {
473
+ // Combine the surrogate pair and store it escaped.
474
+ result += encodeHex ( ( char - 0xD800 ) * 0x400 + nextChar - 0xDC00 + 0x10000 ) ;
475
+ // Advance index one extra since we already used that char here.
476
+ i ++ ; continue ;
477
+ }
478
+ }
469
479
escapeSeq = ESCAPE_SEQUENCES [ char ] ;
470
480
result += ! escapeSeq && isPrintable ( char )
471
481
? string [ i ]
You can’t perform that action at this time.
0 commit comments