mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Auto merge of #24870 - pshaughn:2909, r=jdm
Fix #2909 (squashed version of PR #24865) <!-- Please describe your changes on the following line: --> Now using data-url::forgiving_base64 instead of base64, this fixes all the fetch/data-urls/base64.* tests. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes do not quite fix yet #2909 <!-- Either: --> - [X] There are tests for these changes OR - [ ] These changes do not require tests because ___ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
This commit is contained in:
commit
81c59077fd
4 changed files with 17 additions and 41 deletions
10
Cargo.lock
generated
10
Cargo.lock
generated
|
@ -1021,6 +1021,15 @@ dependencies = [
|
||||||
"syn 1.0.3",
|
"syn 1.0.3",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "data-url"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d33fe99ccedd6e84bc035f1931bb2e6be79739d6242bd895e7311c886c50dc9c"
|
||||||
|
dependencies = [
|
||||||
|
"matches",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "dbus"
|
name = "dbus"
|
||||||
version = "0.6.3"
|
version = "0.6.3"
|
||||||
|
@ -3460,6 +3469,7 @@ dependencies = [
|
||||||
"content-security-policy",
|
"content-security-policy",
|
||||||
"cookie",
|
"cookie",
|
||||||
"crossbeam-channel",
|
"crossbeam-channel",
|
||||||
|
"data-url",
|
||||||
"devtools_traits",
|
"devtools_traits",
|
||||||
"embedder_traits",
|
"embedder_traits",
|
||||||
"flate2",
|
"flate2",
|
||||||
|
|
|
@ -20,6 +20,7 @@ bytes = "0.4"
|
||||||
content-security-policy = {version = "0.3.0", features = ["serde"]}
|
content-security-policy = {version = "0.3.0", features = ["serde"]}
|
||||||
cookie_rs = {package = "cookie", version = "0.11"}
|
cookie_rs = {package = "cookie", version = "0.11"}
|
||||||
crossbeam-channel = "0.3"
|
crossbeam-channel = "0.3"
|
||||||
|
data-url = "0.1.0"
|
||||||
devtools_traits = {path = "../devtools_traits"}
|
devtools_traits = {path = "../devtools_traits"}
|
||||||
embedder_traits = { path = "../embedder_traits" }
|
embedder_traits = { path = "../embedder_traits" }
|
||||||
flate2 = "1"
|
flate2 = "1"
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use base64;
|
use data_url::forgiving_base64;
|
||||||
use mime::Mime;
|
use mime::Mime;
|
||||||
use percent_encoding::percent_decode;
|
use percent_encoding::percent_decode;
|
||||||
use servo_url::ServoUrl;
|
use servo_url::ServoUrl;
|
||||||
|
@ -16,6 +16,10 @@ pub enum DecodeError {
|
||||||
pub type DecodeData = (Mime, Vec<u8>);
|
pub type DecodeData = (Mime, Vec<u8>);
|
||||||
|
|
||||||
pub fn decode(url: &ServoUrl) -> Result<DecodeData, DecodeError> {
|
pub fn decode(url: &ServoUrl) -> Result<DecodeData, DecodeError> {
|
||||||
|
// data_url could do all of this work for us,
|
||||||
|
// except that it currently (Nov 2019) parses mime types into a
|
||||||
|
// different Mime class than other code expects
|
||||||
|
|
||||||
assert_eq!(url.scheme(), "data");
|
assert_eq!(url.scheme(), "data");
|
||||||
// Split out content type and data.
|
// Split out content type and data.
|
||||||
let parts: Vec<&str> = url[Position::BeforePath..Position::AfterQuery]
|
let parts: Vec<&str> = url[Position::BeforePath..Position::AfterQuery]
|
||||||
|
@ -44,13 +48,7 @@ pub fn decode(url: &ServoUrl) -> Result<DecodeData, DecodeError> {
|
||||||
|
|
||||||
let mut bytes = percent_decode(parts[1].as_bytes()).collect::<Vec<_>>();
|
let mut bytes = percent_decode(parts[1].as_bytes()).collect::<Vec<_>>();
|
||||||
if is_base64 {
|
if is_base64 {
|
||||||
// FIXME(#2909): It’s unclear what to do with non-alphabet characters,
|
match forgiving_base64::decode_to_vec(&bytes) {
|
||||||
// but Acid 3 apparently depends on spaces being ignored.
|
|
||||||
bytes = bytes
|
|
||||||
.into_iter()
|
|
||||||
.filter(|&b| b != b' ')
|
|
||||||
.collect::<Vec<u8>>();
|
|
||||||
match base64::decode_config(&bytes, base64::STANDARD.decode_allow_trailing_bits(true)) {
|
|
||||||
Err(..) => return Err(DecodeError::NonBase64DataUri),
|
Err(..) => return Err(DecodeError::NonBase64DataUri),
|
||||||
Ok(data) => bytes = data,
|
Ok(data) => bytes = data,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,33 +0,0 @@
|
||||||
[base64.any.worker.html]
|
|
||||||
[data: URL base64 handling: "ab="]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[data: URL base64 handling: "ab\\fcd"]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[data: URL base64 handling: "ab\\t\\n\\f\\r cd"]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[data: URL base64 handling: " \\t\\n\\f\\r ab\\t\\n\\f\\r cd\\t\\n\\f\\r "]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[data: URL base64 handling: "ab\\t\\n\\f\\r =\\t\\n\\f\\r =\\t\\n\\f\\r "]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
|
|
||||||
[base64.any.html]
|
|
||||||
[data: URL base64 handling: "ab="]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[data: URL base64 handling: "ab\\fcd"]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[data: URL base64 handling: "ab\\t\\n\\f\\r cd"]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[data: URL base64 handling: " \\t\\n\\f\\r ab\\t\\n\\f\\r cd\\t\\n\\f\\r "]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[data: URL base64 handling: "ab\\t\\n\\f\\r =\\t\\n\\f\\r =\\t\\n\\f\\r "]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue