@@ -59,6 +59,7 @@ function Parser() {
5959 this . stringBuffer = Buffer . alloc ? Buffer . alloc ( STRING_BUFFER_SIZE ) : new Buffer ( STRING_BUFFER_SIZE ) ;
6060 this . stringBufferOffset = 0 ;
6161 this . unicode = undefined ; // unicode escapes
62+ this . highSurrogate = undefined ;
6263
6364 this . key = undefined ;
6465 this . mode = undefined ;
@@ -217,8 +218,20 @@ proto.write = function (buffer) {
217218 if ( ( n >= 0x30 && n < 0x40 ) || ( n > 0x40 && n <= 0x46 ) || ( n > 0x60 && n <= 0x66 ) ) {
218219 this . unicode += String . fromCharCode ( n ) ;
219220 if ( this . tState ++ === STRING6 ) {
220- this . appendStringBuf ( Buffer ( String . fromCharCode ( parseInt ( this . unicode , 16 ) ) ) ) ;
221+ var intVal = parseInt ( this . unicode , 16 ) ;
221222 this . unicode = undefined ;
223+ if ( this . highSurrogate !== undefined && intVal >= 0xDC00 && intVal < ( 0xDFFF + 1 ) ) { //<56320,57343> - lowSurrogate
224+ this . appendStringBuf ( new Buffer ( String . fromCharCode ( this . highSurrogate , intVal ) ) ) ;
225+ this . highSurrogate = undefined ;
226+ } else if ( this . highSurrogate === undefined && intVal >= 0xD800 && intVal < ( 0xDBFF + 1 ) ) { //<55296,56319> - highSurrogate
227+ this . highSurrogate = intVal ;
228+ } else {
229+ if ( this . highSurrogate !== undefined ) {
230+ this . appendStringBuf ( new Buffer ( String . fromCharCode ( this . highSurrogate ) ) ) ;
231+ this . highSurrogate = undefined ;
232+ }
233+ this . appendStringBuf ( new Buffer ( String . fromCharCode ( intVal ) ) ) ;
234+ }
222235 this . tState = STRING1 ;
223236 }
224237 } else {
0 commit comments