Skip to content

Commit

Permalink
Bug 1846780: responseXML is populated for a blob with an empty type. …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
dlrobertson committed Aug 8, 2023
1 parent a117230 commit 2e71051
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
6 changes: 3 additions & 3 deletions dom/xhr/XMLHttpRequestMainThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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>

0 comments on commit 2e71051

Please sign in to comment.