Bug 844007 - PL_strcmp works only if the string is null-terminated. r=hsivonen

This commit is contained in:
Masatoshi Kimura 2013-02-23 21:14:12 +09:00
parent fbd6c3bd44
commit 800aaa7299
3 changed files with 47 additions and 2 deletions

View File

@ -1751,8 +1751,8 @@ ExtractCharsetFromXmlDeclaration(const unsigned char* aBytes, int32_t aLen,
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;

View File

@ -87,6 +87,7 @@ MOCHITEST_FILES = parser_datreader.js \
file_bug716579-16.xhtml^headers^ \
test_bug717180.html \
file_bug717180.html \
test_xml_mislabeled_nobom.html \
$(NULL)
# Test disabled on mobile. See bug 737020.

View File

@ -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>