Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
data: URL base64 handling different from atob()
https://bugs.webkit.org/show_bug.cgi?id=175568 rdar://107982669 Reviewed by Alex Christensen. We really shouldn't have different modes of decoding data: URLs. https://bugs.webkit.org/show_bug.cgi?id=211671 fixed a set of web-platform-tests by introducing a new fetch-specific code path. It was not investigated whether the existing code path ought to be changed as well, apart from determining that there was no test coverage for the difference. This commit adds test coverage and aligns WebKit with other browsers and the Fetch standard by removing the legacy code path altogether. * LayoutTests/imported/w3c/web-platform-tests/fetch/data-urls/navigate.window-expected.txt: Added. * LayoutTests/imported/w3c/web-platform-tests/fetch/data-urls/navigate.window.html: Added. * LayoutTests/imported/w3c/web-platform-tests/fetch/data-urls/navigate.window.js: Added. (forEach): (async input): * LayoutTests/imported/w3c/web-platform-tests/fetch/data-urls/w3c-import.log: These changes are being upstreamed via web-platform-tests/wpt#39542. * Source/WebCore/loader/ResourceLoader.cpp: (WebCore::ResourceLoader::loadDataURL): * Source/WebCore/platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm: (WebCore::DataURLResourceMediaLoader::DataURLResourceMediaLoader): * Source/WebCore/platform/network/DataURLDecoder.cpp: (WebCore::DataURLDecoder::decodeSynchronously): (WebCore::DataURLDecoder::decode): (WebCore::DataURLDecoder::decodeBase64): Deleted. * Source/WebCore/platform/network/DataURLDecoder.h: * Source/WebKit/NetworkProcess/soup/NetworkDataTaskSoup.cpp: (WebKit::NetworkDataTaskSoup::resume): * Source/WebKit/WebProcess/Network/WebLoaderStrategy.cpp: (WebKit::WebLoaderStrategy::loadDataURLSynchronously): Canonical link: https://commits.webkit.org/262976@main
- Loading branch information
Showing
10 changed files
with
99 additions
and
38 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
LayoutTests/imported/w3c/web-platform-tests/fetch/data-urls/navigate.window-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
PASS Nothing fancy | ||
PASS base64 | ||
PASS base64 with code points that differ from base64url | ||
PASS ASCII whitespace in the input is removed | ||
PASS base64 with incorrect padding | ||
PASS base64url is not supported | ||
PASS Vertical tab in the input leads to an error | ||
|
1 change: 1 addition & 0 deletions
1
LayoutTests/imported/w3c/web-platform-tests/fetch/data-urls/navigate.window.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<!-- This file is required for WebKit test infrastructure to run the templated test --> |
75 changes: 75 additions & 0 deletions
75
LayoutTests/imported/w3c/web-platform-tests/fetch/data-urls/navigate.window.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// META: timeout=long | ||
// | ||
// Test some edge cases around navigation to data: URLs to ensure they use the same code path | ||
|
||
[ | ||
{ | ||
input: "data:text/html,<script>parent.postMessage(1, '*')</script>", | ||
result: 1, | ||
name: "Nothing fancy", | ||
}, | ||
{ | ||
input: "data:text/html;base64,PHNjcmlwdD5wYXJlbnQucG9zdE1lc3NhZ2UoMiwgJyonKTwvc2NyaXB0Pg==", | ||
result: 2, | ||
name: "base64", | ||
}, | ||
{ | ||
input: "data:text/html;base64,PHNjcmlwdD5wYXJlbnQucG9zdE1lc3NhZ2UoNCwgJyonKTwvc2NyaXB0Pr+/", | ||
result: 4, | ||
name: "base64 with code points that differ from base64url" | ||
}, | ||
{ | ||
input: "data:text/html;base64,PHNjcml%09%20%20%0A%0C%0DwdD5wYXJlbnQucG9zdE1lc3NhZ2UoNiwgJyonKTwvc2NyaXB0Pg==", | ||
result: 6, | ||
name: "ASCII whitespace in the input is removed" | ||
} | ||
].forEach(({ input, result, name }) => { | ||
// Use promise_test so they go sequentially | ||
promise_test(async t => { | ||
const event = await new Promise((resolve, reject) => { | ||
self.addEventListener("message", t.step_func(resolve), { once: true }); | ||
const frame = document.body.appendChild(document.createElement("iframe")); | ||
t.add_cleanup(() => frame.remove()); | ||
|
||
// The assumption is that postMessage() is quicker | ||
t.step_timeout(reject, 500); | ||
frame.src = input; | ||
}); | ||
assert_equals(event.data, result); | ||
}, name); | ||
}); | ||
|
||
// Failure cases | ||
[ | ||
{ | ||
input: "data:text/html;base64,PHNjcmlwdD5wYXJlbnQucG9zdE1lc3NhZ2UoMywgJyonKTwvc2NyaXB0Pg=", | ||
name: "base64 with incorrect padding", | ||
}, | ||
{ | ||
input: "data:text/html;base64,PHNjcmlwdD5wYXJlbnQucG9zdE1lc3NhZ2UoNSwgJyonKTwvc2NyaXB0Pr-_", | ||
name: "base64url is not supported" | ||
}, | ||
{ | ||
input: "data:text/html;base64,%0BPHNjcmlwdD5wYXJlbnQucG9zdE1lc3NhZ2UoNywgJyonKTwvc2NyaXB0Pg==", | ||
name: "Vertical tab in the input leads to an error" | ||
} | ||
].forEach(({ input, name }) => { | ||
// Continue to use promise_test so they go sequentially | ||
promise_test(async t => { | ||
const event = await new Promise((resolve, reject) => { | ||
self.addEventListener("message", t.step_func(reject), { once: true }); | ||
const frame = document.body.appendChild(document.createElement("iframe")); | ||
t.add_cleanup(() => frame.remove()); | ||
|
||
// The assumption is that postMessage() is quicker | ||
t.step_timeout(resolve, 500); | ||
frame.src = input; | ||
}); | ||
}, name); | ||
}); | ||
|
||
// I found some of the interesting code point cases above through brute force: | ||
// | ||
// for (i = 0; i < 256; i++) { | ||
// w(btoa("<script>parent.postMessage(5, '*')<\/script>" + String.fromCodePoint(i) + String.fromCodePoint(i))); | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters