Index: Source/wtf/text/TextCodecUTF8.cpp |
diff --git a/Source/wtf/text/TextCodecUTF8.cpp b/Source/wtf/text/TextCodecUTF8.cpp |
index ce595b34619709488d0e20aa31b955afaeeb08f3..81197c77e534d3d495062ab480909c7f5ec0d210 100644 |
--- a/Source/wtf/text/TextCodecUTF8.cpp |
+++ b/Source/wtf/text/TextCodecUTF8.cpp |
@@ -436,6 +436,10 @@ CString TextCodecUTF8::encodeCommon(const CharType* characters, size_t length) |
while (i < length) { |
UChar32 character; |
U16_NEXT(characters, i, length, character); |
+ // U16_NEXT will simply emit a surrogate code point if an unmatched surrogate |
+ // is encountered; we must convert it to a U+FFFD (REPLACEMENT CHARACTER) here. |
+ if (0xD800 <= character && character <= 0xDFFF) |
+ character = replacementCharacter; |
U8_APPEND_UNSAFE(bytes.data(), bytesWritten, character); |
} |