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

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: Rebased Created 6 years, 8 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: Source/modules/encoding/TextDecoder.cpp
diff --git a/Source/modules/encoding/TextDecoder.cpp b/Source/modules/encoding/TextDecoder.cpp
index 84df22cad1c6f5b8fa545d123d5e612747d6da51..9e93b705f5d49b742a96c514226dbfb7420a50e4 100644
--- a/Source/modules/encoding/TextDecoder.cpp
+++ b/Source/modules/encoding/TextDecoder.cpp
@@ -51,14 +51,18 @@ TextDecoder* TextDecoder::create(const String& label, const Dictionary& options,
bool fatal = false;
options.get("fatal", fatal);
- return new TextDecoder(encoding.name(), fatal);
+ bool ignoreBOM = false;
+ options.get("ignoreBOM", ignoreBOM);
+
+ return new TextDecoder(encoding.name(), fatal, ignoreBOM);
}
-TextDecoder::TextDecoder(const String& encoding, bool fatal)
+TextDecoder::TextDecoder(const String& encoding, bool fatal, bool ignoreBOM)
: m_encoding(encoding)
, m_codec(newTextCodec(m_encoding))
, m_fatal(fatal)
+ , m_ignoreBOM(ignoreBOM)
, m_bomSeen(false)
{
}
@@ -95,7 +99,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)

Powered by Google App Engine
This is Rietveld 408576698