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

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

Issue 2781363003: Respect UTF-8 detection result for local file resources (Closed)
Patch Set: Created 3 years, 9 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 | « no previous file | third_party/WebKit/Source/platform/text/TextEncodingDetectorTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 e4fc5d0c2bfc4b6bcaaeca18c9171875cc19869b..55b21ec29a261fd1f7e3201648063e5336af8d62 100644
--- a/third_party/WebKit/Source/platform/text/TextEncodingDetector.cpp
+++ b/third_party/WebKit/Source/platform/text/TextEncodingDetector.cpp
@@ -30,6 +30,7 @@
#include "platform/text/TextEncodingDetector.h"
+#include "platform/weborigin/KURL.h"
#include "third_party/ced/src/compact_enc_det/compact_enc_det.h"
#include "wtf/text/TextEncoding.h"
@@ -56,10 +57,12 @@ bool detectTextEncoding(const char* data,
// Should return false if the detected encoding is UTF8. This helps prevent
// modern web sites from neglecting proper encoding labelling and simply
// relying on browser-side encoding detection. Encoding detection is supposed
- // to work for web sites with legacy encoding only. Detection failure leads
- // |TextResourceDecoder| to use its default encoding determined from system
- // locale or TLD.
- if (encoding == UNKNOWN_ENCODING || encoding == UTF8)
+ // to work for web sites with legacy encoding only (so this doesn't have to
+ // be applied to local file resources).
+ // Detection failure leads |TextResourceDecoder| to use its default encoding
+ // determined from system locale or TLD.
+ String protocol = hintUrl ? KURL(ParsedURLString, hintUrl).protocol() : "";
+ if (encoding == UNKNOWN_ENCODING || (protocol != "file" && encoding == UTF8))
return false;
// Map all the Shift-JIS variants to Shift-JIS.
« no previous file with comments | « no previous file | third_party/WebKit/Source/platform/text/TextEncodingDetectorTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698