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

Unified Diff: third_party/WebKit/Source/platform/text/TextEncodingDetectorTest.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
« no previous file with comments | « third_party/WebKit/Source/platform/text/TextEncodingDetector.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/platform/text/TextEncodingDetectorTest.cpp
diff --git a/third_party/WebKit/Source/platform/text/TextEncodingDetectorTest.cpp b/third_party/WebKit/Source/platform/text/TextEncodingDetectorTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..fc5d2ac3a9cacbf09e93de07513a0fb83b02b05b
--- /dev/null
+++ b/third_party/WebKit/Source/platform/text/TextEncodingDetectorTest.cpp
@@ -0,0 +1,33 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "platform/text/TextEncodingDetector.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+#include "wtf/text/TextEncoding.h"
+
+namespace blink {
+
+TEST(TextResourceDecoderTest, RespectIso2022Jp)
+{
+ // ISO-2022-JP is the only 7-bit encoding defined in WHATWG standard.
+ std::string iso2022jp = " \x1B""$BKL3$F;F|K\\%O%`%U%!%$%?!<%:$,%=%U%H%P%s%/$H$N%W%l!<%*%U$r@)$7!\"";
+ WTF::TextEncoding encoding;
+ bool result = detectTextEncoding(iso2022jp.c_str(), iso2022jp.length(), nullptr, &encoding);
+ EXPECT_TRUE(result);
+ EXPECT_EQ(WTF::TextEncoding("ISO-2022-JP"), encoding);
+}
+
+TEST(TextResourceDecoderTest, Ignore7BitEncoding)
+{
+ // 7-bit encodings except ISO-2022-JP are not supported by WHATWG.
+ // They should be detected as plain text (US-ASCII).
+ std::string hzGb2312 = " ~{\x54\x42\x31\x7D\x37\x22\x55\x39\x35\x3D\x3D\x71~} abc";
+ WTF::TextEncoding encoding;
+ bool result = detectTextEncoding(hzGb2312.c_str(), hzGb2312.length(), nullptr, &encoding);
+ EXPECT_TRUE(result);
+ EXPECT_EQ(WTF::TextEncoding("US-ASCII"), encoding);
+}
+
+} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/platform/text/TextEncodingDetector.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698