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

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

Issue 19845004: Do not normalize into NFC the values of form fields (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add normalizeAndEncode() Created 7 years, 5 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 | « Source/wtf/text/TextEncoding.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/wtf/text/TextEncoding.cpp
diff --git a/Source/wtf/text/TextEncoding.cpp b/Source/wtf/text/TextEncoding.cpp
index 90a31d487f99ff88e57b3ff08605d7a6e8429242..3164bc414caa6595a0d51cac4d6ddd965efeb31a 100644
--- a/Source/wtf/text/TextEncoding.cpp
+++ b/Source/wtf/text/TextEncoding.cpp
@@ -72,6 +72,23 @@ CString TextEncoding::encode(const String& string, UnencodableHandling handling)
if (string.isEmpty())
return "";
+ OwnPtr<TextCodec> textCodec = newTextCodec(*this);
+ CString encodedString;
+ if (string.is8Bit())
+ encodedString = textCodec->encode(string.characters8(), string.length(), handling);
+ else
+ encodedString = textCodec->encode(string.characters16(), string.length(), handling);
+ return encodedString;
+}
+
+CString TextEncoding::normalizeAndEncode(const String& string, UnencodableHandling handling) const
+{
+ if (!m_name)
+ return CString();
+
+ if (string.isEmpty())
+ return "";
+
// Text exclusively containing Latin-1 characters (U+0000..U+00FF) is left
// unaffected by NFC. This is effectively the same as saying that all
// Latin-1 text is already normalized to NFC.
@@ -79,18 +96,13 @@ CString TextEncoding::encode(const String& string, UnencodableHandling handling)
if (string.is8Bit())
return newTextCodec(*this)->encode(string.characters8(), string.length(), handling);
- // FIXME: What's the right place to do normalization?
- // It's a little strange to do it inside the encode function.
- // Perhaps normalization should be an explicit step done before calling encode.
-
const UChar* source = string.characters16();
size_t length = string.length();
- Vector<UChar> normalizedCharacters;
-
UErrorCode err = U_ZERO_ERROR;
if (unorm_quickCheck(source, length, UNORM_NFC, &err) != UNORM_YES) {
// First try using the length of the original string, since normalization to NFC rarely increases length.
+ Vector<UChar> normalizedCharacters;
abarth-chromium 2013/07/24 18:20:09 Moving this declaration inside the if statement ca
normalizedCharacters.grow(length);
int32_t normalizedLength = unorm_normalize(source, length, UNORM_NFC, 0, normalizedCharacters.data(), length, &err);
if (err == U_BUFFER_OVERFLOW_ERROR) {
« no previous file with comments | « Source/wtf/text/TextEncoding.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698