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

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

Issue 145973021: Implement "replacement" text encoding. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Replacement codec should emit U+FFFD Created 6 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
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);
}

Powered by Google App Engine
This is Rietveld 408576698