mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 02:14:43 +00:00
Bug 1846780: responseXML is populated for a blob with an empty type. r=twisniewski
A blob with an empty content type or any other invalid content type should return a value for responseXML. Differential Revision: https://phabricator.services.mozilla.com/D185185
This commit is contained in:
parent
a117230132
commit
2e71051f28
@ -2061,9 +2061,9 @@ XMLHttpRequestMainThread::OnStartRequest(nsIRequest* request) {
|
||||
} else {
|
||||
mIsHtml = true;
|
||||
}
|
||||
} else if (!(type.EqualsLiteral("text/xml") ||
|
||||
type.EqualsLiteral("application/xml") ||
|
||||
StringEndsWith(type, "+xml"_ns))) {
|
||||
} else if (!type.IsEmpty() && (!(type.EqualsLiteral("text/xml") ||
|
||||
type.EqualsLiteral("application/xml") ||
|
||||
StringEndsWith(type, "+xml"_ns)))) {
|
||||
// Follow https://xhr.spec.whatwg.org/
|
||||
// If final MIME type is not null, text/html, text/xml, application/xml,
|
||||
// or does not end in +xml, return null.
|
||||
|
@ -0,0 +1,49 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>XMLHttpRequest: responseXML content-type test</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<link rel="help" href="https://xhr.spec.whatwg.org/#dom-xmlhttprequest-responsexml"/>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
<script>
|
||||
|
||||
function parseBlob(blob) {
|
||||
return new Promise(resolve => {
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", URL.createObjectURL(blob));
|
||||
xhr.onload = () => {
|
||||
resolve(xhr.responseXML);
|
||||
}
|
||||
xhr.send();
|
||||
});
|
||||
}
|
||||
|
||||
promise_test(async function() {
|
||||
let blob = new Blob(["<x></x>"]);
|
||||
let responseXML = await parseBlob(blob);
|
||||
assert_not_equals(responseXML, null);
|
||||
}, "Empty MIME type should be equivalent to text/xml")
|
||||
|
||||
promise_test(async function() {
|
||||
let blob = new Blob(["<x></x>"], {type: "text/html"});
|
||||
let responseXML = await parseBlob(blob);
|
||||
assert_equals(responseXML, null);
|
||||
}, "HTML content type should return null")
|
||||
|
||||
promise_test(async function() {
|
||||
let blob = new Blob(["<x></x>"], {type: "text/plain"});
|
||||
let responseXML = await parseBlob(blob);
|
||||
assert_equals(responseXML, null);
|
||||
}, "Non XML or HTML content type should return null")
|
||||
|
||||
promise_test(async function() {
|
||||
let blob = new Blob(["<x></x>"], {type: "text/xml"});
|
||||
let responseXML = await parseBlob(blob);
|
||||
assert_not_equals(responseXML, null);
|
||||
}, "XML content type should parse")
|
||||
|
||||
</script>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user