Index: Source/modules/encoding/TextDecoder.cpp |
diff --git a/Source/modules/encoding/TextDecoder.cpp b/Source/modules/encoding/TextDecoder.cpp |
index 541540e6674acd489317f1660689209f67eec0a7..15dc9a9f1c9b33079a11ca9bc1393e143f00fe0d 100644 |
--- a/Source/modules/encoding/TextDecoder.cpp |
+++ b/Source/modules/encoding/TextDecoder.cpp |
@@ -43,7 +43,7 @@ PassRefPtrWillBeRawPtr<TextDecoder> TextDecoder::create(const String& label, con |
const String& encodingLabel = label.isNull() ? String("utf-8") : label; |
WTF::TextEncoding encoding(encodingLabel); |
- if (!encoding.isValid()) { |
+ if (!encoding.isValid() || !strcmp(encoding.name(), "replacement")) { |
exceptionState.throwTypeError("The encoding label provided ('" + encodingLabel + "') is invalid."); |
return nullptr; |
} |
@@ -51,13 +51,12 @@ PassRefPtrWillBeRawPtr<TextDecoder> TextDecoder::create(const String& label, con |
bool fatal = false; |
options.get("fatal", fatal); |
- return adoptRefWillBeNoop(new TextDecoder(encoding.name(), fatal)); |
+ return adoptRefWillBeNoop(new TextDecoder(encodingLabel, encoding.name(), fatal)); |
} |
- |
-TextDecoder::TextDecoder(const String& encoding, bool fatal) |
- : m_encoding(encoding) |
- , m_codec(newTextCodec(m_encoding)) |
+TextDecoder::TextDecoder(const String& label, const String& name, bool fatal) |
+ : m_encoding(name) |
+ , m_codec(newTextCodec(label)) |
, m_fatal(fatal) |
, m_bomSeen(false) |
{ |
@@ -69,7 +68,7 @@ TextDecoder::~TextDecoder() |
String TextDecoder::encoding() const |
{ |
- String name = String(m_encoding.name()).lower(); |
+ String name = m_encoding.lower(); |
// Where possible, encoding aliases should be handled by changes to Chromium's ICU or Blink's WTF. |
// The same codec is used, but WTF maintains a different name/identity for these. |
if (name == "iso-8859-1" || name == "us-ascii") |
@@ -97,8 +96,7 @@ String TextDecoder::decode(ArrayBufferView* input, const Dictionary& options, Ex |
if (!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) |
+ if ((m_encoding == "UTF-8" || m_encoding == "UTF-16LE" || m_encoding == "UTF-16BE") && s[0] == 0xFEFF) |
s.remove(0); |
} |