Bug 1615897 - Blob URL should not ignore query parameter and revokeObjectURL additionally should not ignore fragments. r=baku

Differential Revision: https://phabricator.services.mozilla.com/D63939

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Tom Schuster 2020-02-25 07:56:07 +00:00
Родитель 6d211bdade
Коммит 2f52c3fd94
6 изменённых файлов: 20 добавлений и 65 удалений

Просмотреть файл

@ -13,11 +13,13 @@ var blob = new Blob(['hello world']);
ok(blob, "We have a blob.");
var tests = [
{ part: "", revoke: true },
{ part: "?aa", revoke: false },
{ part: "#bb", revoke: false },
{ part: "?cc#dd", revoke: false },
{ part: "#ee?ff", revoke: false }
{ part: "", revoke: false, ok: true },
{ part: "", revoke: true, ok: false },
{ part: "?aa", revoke: false, ok: false },
{ part: "?cc#dd", revoke: false, ok: false },
// Stripping #fragment on fetch
{ part: "#bb", revoke: false, ok: true },
{ part: "#ee?ff", revoke: false, ok: true }
];
function runTest() {
@ -39,13 +41,13 @@ function runTest() {
xhr.open('GET', url + test.part);
xhr.onload = function() {
ok(!test.revoke, "Not-revoked URL should send()");
ok(test.ok, `URL with "${test.part}" should send()`);
is(xhr.responseText, 'hello world', 'URL: ' + url + test.part);
runTest();
}
xhr.onerror = function() {
ok(test.revoke, "Revoked URL should fail on send()");
ok(!test.ok, `URL with "${test.part}" should fail on send()`);
runTest();
}

Просмотреть файл

@ -90,25 +90,14 @@ static DataInfo* GetDataInfo(const nsACString& aUri,
return nullptr;
}
// Let's remove any fragment from this URI.
int32_t fragmentPos = aUri.FindChar('#');
DataInfo* res;
// Let's remove any fragment and query from this URI.
int32_t hasFragmentPos = aUri.FindChar('#');
int32_t hasQueryPos = aUri.FindChar('?');
int32_t pos = -1;
if (hasFragmentPos >= 0 && hasQueryPos >= 0) {
pos = std::min(hasFragmentPos, hasQueryPos);
} else if (hasFragmentPos >= 0) {
pos = hasFragmentPos;
if (fragmentPos < 0) {
res = gDataTable->Get(aUri);
} else {
pos = hasQueryPos;
}
if (pos < 0) {
gDataTable->Get(aUri, &res);
} else {
gDataTable->Get(StringHead(aUri, pos), &res);
res = gDataTable->Get(StringHead(aUri, fragmentPos));
}
if (!aAlsoIfRevoked && res && res->mRevoked) {

Просмотреть файл

@ -95,6 +95,11 @@ void URL::CreateObjectURL(const GlobalObject& aGlobal, MediaSource& aSource,
void URL::RevokeObjectURL(const GlobalObject& aGlobal, const nsAString& aURL,
ErrorResult& aRv) {
if (aURL.Contains('#')) {
// Don't revoke URLs that contain fragments.
return;
}
if (NS_IsMainThread()) {
URLMainThread::RevokeObjectURL(aGlobal, aURL, aRv);
} else {

Просмотреть файл

@ -6,18 +6,6 @@
expected:
if (os == "mac"): FAIL
[Only exact matches should revoke URLs, using XHR]
expected: FAIL
[Appending a query string should cause XHR to fail]
expected: FAIL
[Only exact matches should revoke URLs, using fetch]
expected: FAIL
[Appending a query string should cause fetch to fail]
expected: FAIL
[Revoke blob URL after creating Request, will fetch]
expected: FAIL

Просмотреть файл

@ -1,21 +1,7 @@
[url-with-fetch.any.html]
[Only exact matches should revoke URLs, using fetch]
expected: FAIL
[Appending a query string should cause fetch to fail]
expected: FAIL
[Revoke blob URL after creating Request, will fetch]
expected: FAIL
[url-with-fetch.any.worker.html]
[Only exact matches should revoke URLs, using fetch]
expected: FAIL
[Appending a query string should cause fetch to fail]
expected: FAIL
[Revoke blob URL after creating Request, will fetch]
expected: FAIL

Просмотреть файл

@ -1,15 +0,0 @@
[url-with-xhr.any.worker.html]
[Only exact matches should revoke URLs, using XHR]
expected: FAIL
[Appending a query string should cause XHR to fail]
expected: FAIL
[url-with-xhr.any.html]
[Only exact matches should revoke URLs, using XHR]
expected: FAIL
[Appending a query string should cause XHR to fail]
expected: FAIL