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

Unified Diff: third_party/WebKit/Source/platform/text/TextEncodingDetector.cpp

Issue 2253803003: Ignore 7-bit encodings (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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
Index: third_party/WebKit/Source/platform/text/TextEncodingDetector.cpp
diff --git a/third_party/WebKit/Source/platform/text/TextEncodingDetector.cpp b/third_party/WebKit/Source/platform/text/TextEncodingDetector.cpp
index abda74b2b62b0e43cb7d1f4395e99bd359ce5ec6..a2674dbf065849d21e84f1831deea4144ad1d991 100644
--- a/third_party/WebKit/Source/platform/text/TextEncodingDetector.cpp
+++ b/third_party/WebKit/Source/platform/text/TextEncodingDetector.cpp
@@ -46,14 +46,26 @@ bool detectTextEncoding(const char* data, size_t length,
EncodingNameAliasToEncoding(hintEncodingName),
UNKNOWN_LANGUAGE,
CompactEncDet::WEB_CORPUS,
- false, // Include 7-bit encodings
+ false, // Include 7-bit encodings to detect ISO-2022-JP
&consumedBytes,
&isReliable);
- if (encoding != UNKNOWN_ENCODING) {
- *detectedEncoding = WTF::TextEncoding(MimeEncodingName(encoding));
- return true;
+ if (encoding == UNKNOWN_ENCODING)
+ return false;
+
+ // 7-bit encodings (except ISO-2022-JP) are not supported in WHATWG encoding
+ // standard. Mark them as ASCII to keep the raw bytes intact.
+ switch (encoding) {
+ case HZ_GB_2312:
+ case ISO_2022_KR:
+ case ISO_2022_CN:
+ case UTF7:
+ encoding = ASCII_7BIT;
+ break;
+ default:
+ break;
}
- return false;
+ *detectedEncoding = WTF::TextEncoding(MimeEncodingName(encoding));
+ return true;
}
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698