Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1161)

Unified Diff: Source/wtf/text/TextCodecUTF8.cpp

Issue 23601010: Make UTF-8 encoding of unpaired surrogates match Encoding standard (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebased test results Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « LayoutTests/fast/encoding/char-encoding-expected.txt ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
}
« no previous file with comments | « LayoutTests/fast/encoding/char-encoding-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698