@@ -1023,15 +1023,23 @@ class GenericReader {
1023
1023
is.Take ();
1024
1024
unsigned codepoint = ParseHex4 (is, escapeOffset);
1025
1025
RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
1026
- if (RAPIDJSON_UNLIKELY (codepoint >= 0xD800 && codepoint <= 0xDBFF )) {
1027
- // Handle UTF-16 surrogate pair
1028
- if (RAPIDJSON_UNLIKELY (!Consume (is, ' \\ ' ) || !Consume (is, ' u' )))
1029
- RAPIDJSON_PARSE_ERROR (kParseErrorStringUnicodeSurrogateInvalid , escapeOffset);
1030
- unsigned codepoint2 = ParseHex4 (is, escapeOffset);
1031
- RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
1032
- if (RAPIDJSON_UNLIKELY (codepoint2 < 0xDC00 || codepoint2 > 0xDFFF ))
1026
+ if (RAPIDJSON_UNLIKELY (codepoint >= 0xD800 && codepoint <= 0xDFFF )) {
1027
+ // high surrogate, check if followed by valid low surrogate
1028
+ if (RAPIDJSON_LIKELY (codepoint <= 0xDBFF )) {
1029
+ // Handle UTF-16 surrogate pair
1030
+ if (RAPIDJSON_UNLIKELY (!Consume (is, ' \\ ' ) || !Consume (is, ' u' )))
1031
+ RAPIDJSON_PARSE_ERROR (kParseErrorStringUnicodeSurrogateInvalid , escapeOffset);
1032
+ unsigned codepoint2 = ParseHex4 (is, escapeOffset);
1033
+ RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
1034
+ if (RAPIDJSON_UNLIKELY (codepoint2 < 0xDC00 || codepoint2 > 0xDFFF ))
1035
+ RAPIDJSON_PARSE_ERROR (kParseErrorStringUnicodeSurrogateInvalid , escapeOffset);
1036
+ codepoint = (((codepoint - 0xD800 ) << 10 ) | (codepoint2 - 0xDC00 )) + 0x10000 ;
1037
+ }
1038
+ // single low surrogate
1039
+ else
1040
+ {
1033
1041
RAPIDJSON_PARSE_ERROR (kParseErrorStringUnicodeSurrogateInvalid , escapeOffset);
1034
- codepoint = (((codepoint - 0xD800 ) << 10 ) | (codepoint2 - 0xDC00 )) + 0x10000 ;
1042
+ }
1035
1043
}
1036
1044
TEncoding::Encode (os, codepoint);
1037
1045
}
0 commit comments