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

Unified Diff: Source/modules/encoding/TextDecoder.cpp

Issue 232513003: Encoding API: Add ignoreBOM flag to decoder options (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: More explicit test output, correct assertion comment in default case Created 6 years, 7 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/modules/encoding/TextDecoder.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/encoding/TextDecoder.cpp
diff --git a/Source/modules/encoding/TextDecoder.cpp b/Source/modules/encoding/TextDecoder.cpp
index 2d84eb23c6d9fde95eca54fcb8d33f68a4cca3a1..59e5e2603d55acf79e50a07ef99bdde965994d4b 100644
--- a/Source/modules/encoding/TextDecoder.cpp
+++ b/Source/modules/encoding/TextDecoder.cpp
@@ -54,14 +54,18 @@ TextDecoder* TextDecoder::create(const String& label, const Dictionary& options,
bool fatal = false;
options.get("fatal", fatal);
- return new TextDecoder(encoding, fatal);
+ bool ignoreBOM = false;
+ options.get("ignoreBOM", ignoreBOM);
+
+ return new TextDecoder(encoding, fatal, ignoreBOM);
}
-TextDecoder::TextDecoder(const WTF::TextEncoding& encoding, bool fatal)
+TextDecoder::TextDecoder(const WTF::TextEncoding& encoding, bool fatal, bool ignoreBOM)
: m_encoding(encoding)
, m_codec(newTextCodec(encoding))
, m_fatal(fatal)
+ , m_ignoreBOM(ignoreBOM)
, m_bomSeen(false)
{
}
@@ -98,7 +102,7 @@ String TextDecoder::decode(ArrayBufferView* input, const Dictionary& options, Ex
return String();
}
- if (!m_bomSeen && !s.isEmpty()) {
+ if (!m_ignoreBOM && !m_bomSeen && !s.isEmpty()) {
m_bomSeen = true;
String name(m_encoding.name());
if ((name == "UTF-8" || name == "UTF-16LE" || name == "UTF-16BE") && s[0] == 0xFEFF)
« no previous file with comments | « Source/modules/encoding/TextDecoder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698