Fix UTF32Char to String conversion for invalid unicode characters
Invalid, isolated surrogate pairs, UTF32 characters should handled specially and converted to UniChars first
This commit is contained in:
@@ -66,7 +66,7 @@
|
||||
[HTMLInputStreamReaderErrors emitParseError:HTMLStreamReaderErrorIsolatedLowSurrogate
|
||||
atLocation:_location
|
||||
andCallback:_errorCallback];
|
||||
return REPLACEMENT_CHAR;
|
||||
return nextInputCharacter;
|
||||
}
|
||||
|
||||
if (CFStringIsSurrogateHighCharacter(nextInputCharacter)) {
|
||||
@@ -75,7 +75,7 @@
|
||||
[HTMLInputStreamReaderErrors emitParseError:HTMLStreamReaderErrorIsolatedHighSurrogate
|
||||
atLocation:_location
|
||||
andCallback:_errorCallback];
|
||||
return REPLACEMENT_CHAR;
|
||||
return nextInputCharacter;
|
||||
}
|
||||
|
||||
nextInputCharacter = CFStringGetLongCharacterForSurrogatePair(nextInputCharacter, surrogateLow);
|
||||
|
||||
@@ -175,5 +175,7 @@ NS_INLINE NSString * StringFromUniChar(unichar character)
|
||||
|
||||
NS_INLINE NSString * StringFromUTF32Char(UTF32Char character)
|
||||
{
|
||||
return [[NSString alloc] initWithBytes:&character length:sizeof(character) encoding:NSUTF32LittleEndianStringEncoding];
|
||||
unichar pair[2];
|
||||
Boolean isPair = CFStringGetSurrogatePairForLongCharacter(character, pair);
|
||||
return [[NSString alloc] initWithCharacters:(const unichar *)&pair length:(isPair ? 2 : 1)];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user