Bug 844007 - PL_strcmp works only if the string is null-terminated. r=hsivonen
authorMasatoshi Kimura <VYV03354@nifty.ne.jp>
Sat, 23 Feb 2013 21:14:12 +0900
changeset 122770 7aebc1dec8f191876aa3f48f5d01b724d1edd193
parent 122768 195e706140d19f4d777e36026c54a21fd9e24ab7
child 122771 bb9e9d8b1d2fe2114f7c4a0a744fbeaea8a23dbd
push id24358
push userphilringnalda@gmail.com
push dateMon, 25 Feb 2013 03:53:19 +0000
treeherdermozilla-central@e48e1afb1899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershsivonen
bugs844007
milestone22.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 844007 - PL_strcmp works only if the string is null-terminated. r=hsivonen
parser/htmlparser/src/nsParser.cpp
parser/htmlparser/tests/mochitest/Makefile.in
parser/htmlparser/tests/mochitest/test_xml_mislabeled_nobom.html
--- a/parser/htmlparser/src/nsParser.cpp
+++ b/parser/htmlparser/src/nsParser.cpp
@@ -1746,18 +1746,18 @@ ExtractCharsetFromXmlDeclaration(const u
           int32_t encStart = 0;
           char q = 0;
           for (++i; i < aLen; ++i) {
             char qi = ((char*) aBytes)[i];
             if (qi == '\'' || qi == '"') {
               if (q && q == qi) {
                 int32_t count = i - encStart;
                 // encoding value is invalid if it is UTF-16
-                if (count > 0 && (0 != PL_strcmp("UTF-16",
-                    (char*) (aBytes + encStart)))) {
+                if (count > 0 && PL_strncasecmp("UTF-16",
+                    (char*) (aBytes + encStart), count)) {
                   oCharset.Assign((char*) (aBytes + encStart), count);
                 }
                 encodingFound = true;
                 break;
               } else {
                 encStart = i + 1;
                 q = qi;
               }
--- a/parser/htmlparser/tests/mochitest/Makefile.in
+++ b/parser/htmlparser/tests/mochitest/Makefile.in
@@ -82,16 +82,17 @@ MOCHITEST_FILES =	parser_datreader.js \
 		file_bug716579-16.html \
 		file_bug716579-16.html^headers^ \
 		file_bug716579-8.xhtml \
 		file_bug716579-8.xhtml^headers^ \
 		file_bug716579-16.xhtml \
 		file_bug716579-16.xhtml^headers^ \
 		test_bug717180.html \
 		file_bug717180.html \
+		test_xml_mislabeled_nobom.html \
 		$(NULL)
 
 # Test disabled on mobile. See bug 737020.
 ifneq ($(OS_TARGET),Android)
 ifndef MOZ_PLATFORM_MAEMO
 		MOCHITEST_FILES += test_bug709083.html
 endif
 endif
new file mode 100644
--- /dev/null
+++ b/parser/htmlparser/tests/mochitest/test_xml_mislabeled_nobom.html
@@ -0,0 +1,44 @@
+<!DOCTYPE html><meta charset=utf-8>
+<title>Test for mislabeled XML entities</title>
+<script src="/tests/SimpleTest/SimpleTest.js"></script>
+<link rel="stylesheet" href="/tests/SimpleTest/test.css" />
+<body>
+<script class="testbody">
+'use strict';
+
+SimpleTest.waitForExplicitFinish();
+
+var encodings = ['utf-8', 'uTf-8', 'UTF-8', 'utf-16', 'uTf-16', 'UTF-16'];
+testxhr(encodings.shift());
+
+function testxhr(encoding) {
+  var xml = '<?xml version="1.0" encoding="' + encoding + '" ?>\n<test>test</test>';
+  var xhr = new XMLHttpRequest();
+  xhr.open('GET', 'data:text/xml,' + xml);
+  xhr.send();
+  xhr.onload = xhr.onerror = function(e) {
+    ok(e.type === 'load', 'Test xhr loading for utf-8 XML labeled with ' + encoding);
+    is(xhr.responseXML.documentElement.textContent, 'test',
+       'Test xhr response for utf-8 XML labeled with ' + encoding);
+    testiframe(encoding, xml);
+  };
+}
+
+function testiframe(encoding, xml) {
+  var iframe = document.createElement('iframe');
+  iframe.src = 'data:text/xml,' + xml;
+  iframe.onload = iframe.onerror = function(e) {
+    ok(e.type === 'load', 'Test iframe loading for utf-8 XML labeled with ' + encoding);
+    is(iframe.contentDocument.documentElement.textContent, 'test',
+       'Test iframe content for utf-8 XML labeled with ' + encoding);
+    if (encodings.length === 0) {
+      SimpleTest.finish();
+    } else {
+      testxhr(encodings.shift());
+    }
+  };
+  document.body.appendChild(iframe);
+}
+</script>
+<div id="display"></div>
+</body>