Bug 1469580 - Ignore charset= in <meta content> if followed by unmatched quote. r=mrbkap
authorHenri Sivonen <hsivonen@hsivonen.fi>
Fri, 14 Dec 2018 17:53:59 +0000
changeset 507655 d02d14a3dd6e
parent 507654 72065a75fc01
child 507656 e5079e6a5c13
child 507911 df705aed115f
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmrbkap
bugs1469580
milestone66.0a1
first release with
nightly linux32
d02d14a3dd6e / 66.0a1 / 20181214220012 / files
nightly linux64
d02d14a3dd6e / 66.0a1 / 20181214220012 / files
nightly mac
d02d14a3dd6e / 66.0a1 / 20181214220012 / files
nightly win32
d02d14a3dd6e / 66.0a1 / 20181214220012 / files
nightly win64
d02d14a3dd6e / 66.0a1 / 20181214220012 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1469580 - Ignore charset= in <meta content> if followed by unmatched quote. r=mrbkap Differential Revision: https://phabricator.services.mozilla.com/D14410
parser/html/javasrc/ElementName.java
parser/html/javasrc/TreeBuilder.java
parser/html/nsHtml5TreeBuilder.cpp
testing/web-platform/tests/html/syntax/parsing/quotes-in-meta.html
--- a/parser/html/javasrc/ElementName.java
+++ b/parser/html/javasrc/ElementName.java
@@ -954,20 +954,20 @@ TreeBuilder.IMAGE);
 public static final ElementName IFRAME = new ElementName("iframe", "iframe", 
 // CPPONLY: NS_NewHTMLIFrameElement,
 // CPPONLY: NS_NewSVGUnknownElement, 
 TreeBuilder.IFRAME | SPECIAL);
 public static final ElementName LINE = new ElementName("line", "line", 
 // CPPONLY: NS_NewHTMLUnknownElement,
 // CPPONLY: NS_NewSVGLineElement, 
 TreeBuilder.OTHER);
-public static final ElementName MARQUEE = new ElementName("marquee", "marquee", 
-// CPPONLY: NS_NewHTMLDivElement,
-// CPPONLY: NS_NewSVGUnknownElement, 
-TreeBuilder.MARQUEE_OR_APPLET | SPECIAL | SCOPING);
+public static final ElementName MARQUEE = new ElementName("marquee", "marquee",
+    // CPPONLY: NS_NewHTMLMarqueeElement,
+    // CPPONLY: NS_NewSVGUnknownElement,
+    TreeBuilder.MARQUEE_OR_APPLET | SPECIAL | SCOPING);
 public static final ElementName POLYLINE = new ElementName("polyline", "polyline", 
 // CPPONLY: NS_NewHTMLUnknownElement,
 // CPPONLY: NS_NewSVGPolylineElement, 
 TreeBuilder.OTHER);
 public static final ElementName PICTURE = new ElementName("picture", "picture", 
 // CPPONLY: NS_NewHTMLPictureElement,
 // CPPONLY: NS_NewSVGUnknownElement, 
 TreeBuilder.OTHER);
--- a/parser/html/javasrc/TreeBuilder.java
+++ b/parser/html/javasrc/TreeBuilder.java
@@ -3293,27 +3293,29 @@ public abstract class TreeBuilder<T> imp
                         case ';':
                             end = i;
                             break charsetloop;
                         default:
                             continue;
                     }
             }
         }
-        String charset = null;
         if (start != -1) {
             if (end == -1) {
+              if (charsetState == CHARSET_UNQUOTED) {
                 end = buffer.length;
+              } else {
+                return null;
+              }
             }
-            charset = Portability.newStringFromBuffer(buffer, start, end
-                    - start
+            return Portability.newStringFromBuffer(buffer, start, end - start
                 // CPPONLY: , tb, false
             );
         }
-        return charset;
+        return null;
     }
 
     private void checkMetaCharset(HtmlAttributes attributes)
             throws SAXException {
         String charset = attributes.getValue(AttributeName.CHARSET);
         if (charset != null) {
             if (tokenizer.internalEncodingDeclaration(charset)) {
                 requestSuspension();
--- a/parser/html/nsHtml5TreeBuilder.cpp
+++ b/parser/html/nsHtml5TreeBuilder.cpp
@@ -2284,25 +2284,28 @@ nsHtml5String nsHtml5TreeBuilder::extrac
             NS_HTML5_BREAK(charsetloop);
           }
           default: { continue; }
         }
       }
     }
   }
 charsetloop_end:;
-  nsHtml5String charset = nullptr;
   if (start != -1) {
     if (end == -1) {
-      end = buffer.length;
+      if (charsetState == CHARSET_UNQUOTED) {
+        end = buffer.length;
+      } else {
+        return nullptr;
+      }
     }
-    charset = nsHtml5Portability::newStringFromBuffer(buffer, start,
-                                                      end - start, tb, false);
+    return nsHtml5Portability::newStringFromBuffer(buffer, start, end - start,
+                                                   tb, false);
   }
-  return charset;
+  return nullptr;
 }
 
 void nsHtml5TreeBuilder::checkMetaCharset(nsHtml5HtmlAttributes* attributes) {
   nsHtml5String charset =
       attributes->getValue(nsHtml5AttributeName::ATTR_CHARSET);
   if (charset) {
     if (tokenizer->internalEncodingDeclaration(charset)) {
       requestSuspension();
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/html/syntax/parsing/quotes-in-meta.html
@@ -0,0 +1,12 @@
+<!doctype html>
+<meta http-equiv="Content-Type" content='charset="windows-1251'>
+<meta charset=windows-1250>
+<title></title>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+<link rel=help href="https://html.spec.whatwg.org/#algorithm-for-extracting-a-character-encoding-from-a-meta-element">
+<script>
+test(function() {
+    assert_equals(document.characterSet, "windows-1250");
+});
+</script>