Bug 213517 - Interpret x-user-defined as windows-1252 in <meta> for compatibility with other browsers. r=smontagu, a=lsblakk
authorHenri Sivonen <hsivonen@hsivonen.fi>
Thu, 02 Jan 2014 09:18:19 +0200
changeset 174554 1d019f592fdfc7087497b363a4846f65a3447409
parent 174553 8c10d0e5d85dbc80f3182e16a2c0327c8b1e176a
child 174555 c31bda611c7963783b46929a2d24e18fb5f06fe3
push id3224
push userlsblakk@mozilla.com
push dateTue, 04 Feb 2014 01:06:49 +0000
treeherdermozilla-beta@60c04d0987f1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmontagu, lsblakk
bugs213517
milestone28.0a2
Bug 213517 - Interpret x-user-defined as windows-1252 in <meta> for compatibility with other browsers. r=smontagu, a=lsblakk
parser/html/nsHtml5MetaScannerCppSupplement.h
parser/html/nsHtml5StreamParser.cpp
parser/htmlparser/tests/mochitest/mochitest.ini
parser/htmlparser/tests/mochitest/test_bug213517.html
--- a/parser/html/nsHtml5MetaScannerCppSupplement.h
+++ b/parser/html/nsHtml5MetaScannerCppSupplement.h
@@ -30,11 +30,16 @@ nsHtml5MetaScanner::tryCharset(nsString*
   if (!EncodingUtils::FindEncodingForLabel(label, encoding)) {
     return false;
   }
   if (encoding.EqualsLiteral("UTF-16BE") ||
       encoding.EqualsLiteral("UTF-16LE")) {
     mCharset.Assign("UTF-8");
     return true;
   }
+  if (encoding.EqualsLiteral("x-user-defined")) {
+    // WebKit/Blink hack for Indian and Armenian legacy sites
+    mCharset.Assign("windows-1252");
+    return true;
+  }
   mCharset.Assign(encoding);
   return true;
 }
--- a/parser/html/nsHtml5StreamParser.cpp
+++ b/parser/html/nsHtml5StreamParser.cpp
@@ -1198,25 +1198,29 @@ nsHtml5StreamParser::PreferredForInterna
   if (!EncodingUtils::FindEncodingForLabel(aEncoding, newEncoding)) {
     // the encoding name is bogus
     mTreeBuilder->MaybeComplainAboutCharset("EncMetaUnsupported",
                                             true,
                                             mTokenizer->getLineNumber());
     return false;
   }
 
-  if (newEncoding.EqualsLiteral("UTF-16") ||
-      newEncoding.EqualsLiteral("UTF-16BE") ||
+  if (newEncoding.EqualsLiteral("UTF-16BE") ||
       newEncoding.EqualsLiteral("UTF-16LE")) {
     mTreeBuilder->MaybeComplainAboutCharset("EncMetaUtf16",
                                             true,
                                             mTokenizer->getLineNumber());
     newEncoding.Assign("UTF-8");
   }
 
+  if (newEncoding.EqualsLiteral("x-user-defined")) {
+    // WebKit/Blink hack for Indian and Armenian legacy sites
+    newEncoding.Assign("windows-1252");
+  }
+
   if (newEncoding.Equals(mCharset)) {
     if (mCharsetSource < kCharsetFromMetaPrescan) {
       if (mInitialEncodingWasFromParentFrame) {
         mTreeBuilder->MaybeComplainAboutCharset("EncLateMetaFrame",
                                                 false,
                                                 mTokenizer->getLineNumber());
       } else {
         mTreeBuilder->MaybeComplainAboutCharset("EncLateMeta",
--- a/parser/htmlparser/tests/mochitest/mochitest.ini
+++ b/parser/htmlparser/tests/mochitest/mochitest.ini
@@ -87,16 +87,17 @@ support-files =
   html5lib_tree_construction/webkit02.dat
   html5lib_tree_construction/main-element.dat
   html5lib_tree_construction/scripted/adoption01.dat
   html5lib_tree_construction/scripted/webkit01.dat
   html5lib_tree_construction/scripted/ark.dat
 
 [test_bug102699.html]
 [test_bug174351.html]
+[test_bug213517.html]
 [test_bug339350.xhtml]
 [test_bug358797.html]
 [test_bug396568.html]
 [test_bug418464.html]
 [test_bug460437.xhtml]
 [test_bug502091.html]
 [test_bug543062.html]
 [test_bug552938-2.html]
new file mode 100644
--- /dev/null
+++ b/parser/htmlparser/tests/mochitest/test_bug213517.html
@@ -0,0 +1,30 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=213517
+-->
+<head>
+  <meta charset="x-user-defined">
+  <title>Test for Bug 213517</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+  <script type="application/javascript">
+
+  /** Test for Bug 213517 **/
+
+  is(document.characterSet, "windows-1252", "x-user-defined in <meta> should have gotten mapped to windows-1252");
+
+
+
+  </script>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=213517">Mozilla Bug 213517</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+</pre>
+</body>
+</html>