Bug 1405696 - pass the document encoding to NS_NewURI for XMLHttpRequest; r=bkelly

MozReview-Commit-ID: IZkWHGZacO0

--HG--
extra : rebase_source : 4cffffd6ce76f49f8515a04cd4f7523e5ceabb1f
This commit is contained in:
Thomas Wisniewski 2017-10-20 20:47:36 -04:00
parent 731489bb3d
commit 34162c2171
2 changed files with 13 additions and 4 deletions

View File

@ -1550,8 +1550,17 @@ XMLHttpRequestMainThread::Open(const nsACString& aMethod,
} else if (responsibleDocument) {
baseURI = responsibleDocument->GetBaseURI();
}
// Use the responsible document's encoding for the URL if we have one,
// except for dedicated workers. Use UTF-8 otherwise.
NotNull<const Encoding*> originCharset = UTF_8_ENCODING;
if (responsibleDocument &&
responsibleDocument->NodePrincipal() == mPrincipal) {
originCharset = responsibleDocument->GetDocumentCharacterSet();
}
nsCOMPtr<nsIURI> parsedURL;
rv = NS_NewURI(getter_AddRefs(parsedURL), aUrl, nullptr, baseURI);
rv = NS_NewURI(getter_AddRefs(parsedURL), aUrl, originCharset, baseURI);
if (NS_FAILED(rv)) {
if (rv == NS_ERROR_MALFORMED_URI) {
return NS_ERROR_DOM_MALFORMED_URI;

View File

@ -14,14 +14,14 @@
var client = new XMLHttpRequest()
client.open("GET", "resources/content.py?\u00DF", false) // This is the German "eszett" character
client.send()
assert_equals(client.getResponseHeader("x-request-query"), "%C3%9F")
assert_equals(client.getResponseHeader("x-request-query"), "%DF")
}, "percent encode characters");
test(function() {
var client = new XMLHttpRequest()
client.open("GET", "resources/content.py?\uD83D", false)
client.send()
assert_equals(client.getResponseHeader("x-request-query"), "%EF%BF%BD")
}, "lone surrogate should return U+FFFD");
assert_equals(client.getResponseHeader("x-request-query"), "&%2365533;")
}, "lone surrogate");
</script>
</body>
</html>