@@ -240,7 +240,7 @@ private function parse($indent, $result = NULL, $key = NULL, $hasKey = FALSE)
240
240
'false ' => FALSE , 'False ' => FALSE , 'FALSE ' => FALSE , 'no ' => FALSE , 'No ' => FALSE , 'NO ' => FALSE , 'off ' => FALSE , 'Off ' => FALSE , 'OFF ' => FALSE ,
241
241
);
242
242
if ($ t [0 ] === '" ' ) {
243
- $ value = preg_replace_callback ('# \\\\(?:u[0-9a-f]{4}|x[0-9a-f]{2}|.)#i ' , array ($ this , 'cbString ' ), substr ($ t , 1 , -1 ));
243
+ $ value = preg_replace_callback ('# \\\\(?:ud[89ab][0-9a-f]{2} \\\\ ud[c-f][0-9a-f]{2}| u[0-9a-f]{4}|x[0-9a-f]{2}|.)#i ' , array ($ this , 'cbString ' ), substr ($ t , 1 , -1 ));
244
244
} elseif ($ t [0 ] === "' " ) {
245
245
$ value = substr ($ t , 1 , -1 );
246
246
} elseif (isset ($ consts [$ t ]) && (!isset ($ tokens [$ n +1 ][0 ]) || ($ tokens [$ n +1 ][0 ] !== ': ' && $ tokens [$ n +1 ][0 ] !== '= ' ))) {
@@ -296,8 +296,14 @@ private function cbString($m)
296
296
$ sq = $ m [0 ];
297
297
if (isset ($ mapping [$ sq [1 ]])) {
298
298
return $ mapping [$ sq [1 ]];
299
- } elseif ($ sq [1 ] === 'u ' && strlen ($ sq ) === 6 ) {
300
- return iconv ('UTF-32BE ' , 'UTF-8//IGNORE ' , pack ('N ' , hexdec (substr ($ sq , 2 ))));
299
+ } elseif ($ sq [1 ] === 'u ' && strlen ($ sq ) >= 6 ) {
300
+ $ lead = hexdec (substr ($ sq , 2 , 4 ));
301
+ $ tail = hexdec (substr ($ sq , 8 , 4 ));
302
+ $ code = $ tail ? (0x2400 + (($ lead - 0xD800 ) << 10 ) + $ tail ) : $ lead ;
303
+ if ($ code >= 0xD800 && $ code <= 0xDFFF ) {
304
+ $ this ->error ("Invalid UTF-8 (lone surrogate) $ sq " );
305
+ }
306
+ return iconv ('UTF-32BE ' , 'UTF-8//IGNORE ' , pack ('N ' , $ code ));
301
307
} elseif ($ sq [1 ] === 'x ' && strlen ($ sq ) === 4 ) {
302
308
return chr (hexdec (substr ($ sq , 2 )));
303
309
} else {
0 commit comments