diff --git a/dom/file/tests/test_blob_fragment_and_query.html b/dom/file/tests/test_blob_fragment_and_query.html index b54e5fd043c0..fa3709c419a5 100644 --- a/dom/file/tests/test_blob_fragment_and_query.html +++ b/dom/file/tests/test_blob_fragment_and_query.html @@ -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(); } diff --git a/dom/file/uri/BlobURLProtocolHandler.cpp b/dom/file/uri/BlobURLProtocolHandler.cpp index e1ca99444e76..8113b461d179 100644 --- a/dom/file/uri/BlobURLProtocolHandler.cpp +++ b/dom/file/uri/BlobURLProtocolHandler.cpp @@ -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) { diff --git a/dom/url/URL.cpp b/dom/url/URL.cpp index e87f93b5717c..d3878b52aae0 100644 --- a/dom/url/URL.cpp +++ b/dom/url/URL.cpp @@ -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 { diff --git a/testing/web-platform/meta/FileAPI/url/sandboxed-iframe.html.ini b/testing/web-platform/meta/FileAPI/url/sandboxed-iframe.html.ini index a58bdca3c1fd..2a7e621f62c1 100644 --- a/testing/web-platform/meta/FileAPI/url/sandboxed-iframe.html.ini +++ b/testing/web-platform/meta/FileAPI/url/sandboxed-iframe.html.ini @@ -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 diff --git a/testing/web-platform/meta/FileAPI/url/url-with-fetch.any.js.ini b/testing/web-platform/meta/FileAPI/url/url-with-fetch.any.js.ini index 9fcaa4cb33f5..ebb43e068f6e 100644 --- a/testing/web-platform/meta/FileAPI/url/url-with-fetch.any.js.ini +++ b/testing/web-platform/meta/FileAPI/url/url-with-fetch.any.js.ini @@ -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 - diff --git a/testing/web-platform/meta/FileAPI/url/url-with-xhr.any.js.ini b/testing/web-platform/meta/FileAPI/url/url-with-xhr.any.js.ini deleted file mode 100644 index 577637090247..000000000000 --- a/testing/web-platform/meta/FileAPI/url/url-with-xhr.any.js.ini +++ /dev/null @@ -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 -