1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-25 16:49:18 -05:00

fix(serde_v8): remove intentional deserialization error on non-utf8 strings (#10156)

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
This commit is contained in:
Aaron O'Mullan 2021-05-19 20:45:48 +02:00 committed by GitHub
parent 24da0aa37d
commit eb56186e44
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 45 deletions

View file

@ -154,12 +154,8 @@ impl<'de, 'a, 'b, 's, 'x> de::Deserializer<'de>
V: Visitor<'de>,
{
if self.input.is_string() {
// TODO(@AaronO): implement a `.to_rust_string -> Option<String>` in rusty-v8
let v8_string = v8::Local::<v8::String>::try_from(self.input).unwrap();
let string = match v8_to_rust_string(self.scope, v8_string) {
Some(string) => string,
None => return Err(Error::ExpectedUtf8),
};
let string = v8_string.to_rust_string_lossy(self.scope);
visitor.visit_string(string)
} else {
Err(Error::ExpectedString)
@ -619,15 +615,3 @@ impl<'de, 'a, 'b, 's> de::VariantAccess<'de>
de::Deserializer::deserialize_struct(&mut d, "", fields, visitor)
}
}
// Like v8::String::to_rust_string_lossy except returns None on non-utf8
fn v8_to_rust_string(
scope: &mut v8::HandleScope,
s: v8::Local<v8::String>,
) -> Option<String> {
let string = s.to_rust_string_lossy(scope);
match string.find(std::char::REPLACEMENT_CHARACTER) {
Some(_) => None,
None => Some(string),
}
}

View file

@ -683,8 +683,6 @@
"Stringification of new URLSearchParams(\"hi=there&thank=you\")"
],
"url-constructor.any.html": [
"Parsing: <https://x/<2F>?<3F>#<23>> against <about:blank>",
"Parsing: <http://example.com/\ud800𐟾\udfff﷐﷏﷯ﷰ￾￿?\ud800𐟾\udfff﷐﷏﷯ﷰ￾￿> against <about:blank>",
"Parsing: <file://%43%7C> against <about:blank>",
"Parsing: <file://%43|> against <about:blank>",
"Parsing: <file://C%7C> against <about:blank>",
@ -740,10 +738,7 @@
"Parsing: <> against <non-spec:/..//p>",
"Parsing: <path> against <non-spec:/..//p>"
],
"url-origin.any.html": [
"Origin parsing: <http://example.com/\ud800𐟾\udfff﷐﷏﷯ﷰ￾￿?\ud800𐟾\udfff﷐﷏﷯ﷰ￾￿> against <about:blank>",
"Origin parsing: <https://x/<2F>?<3F>#<23>> against <about:blank>"
],
"url-origin.any.html": true,
"url-searchparams.any.html": true,
"url-setters-stripping.any.html": [
"Setting protocol with leading U+0000 (https:)",
@ -777,12 +772,7 @@
"urlsearchparams-getall.any.html": true,
"urlsearchparams-has.any.html": true,
"urlsearchparams-set.any.html": true,
"urlsearchparams-sort.any.html": [
"Parse and sort: <20>=x&&<26>=a",
"URL parse and sort: <20>=x&&<26>=a",
"Parse and sort: é&e<>&é",
"URL parse and sort: é&e<>&é"
],
"urlsearchparams-sort.any.html": true,
"urlsearchparams-stringifier.any.html": true
},
"fetch": {
@ -1088,33 +1078,17 @@
"storage_session_window_open.window.html": false,
"storage_set_value_enumerate.window.html": true,
"storage_setitem.window.html": [
"localStorage[\"\ud800\"]",
"localStorage[] = \"\ud800\"",
"localStorage[\"\udbff\"]",
"localStorage[] = \"\udbff\"",
"localStorage[\"\udc00\"]",
"localStorage[] = \"\udc00\"",
"localStorage[\"\udfff\"]",
"localStorage[] = \"\udfff\"",
"localStorage[\"\\ufffd\"]",
"localStorage[] = \"\\ufffd\"",
"localStorage[\"\ud83ca\"]",
"localStorage[] = \"\ud83ca\"",
"localStorage[\"a\udf4d\"]",
"localStorage[] = \"a\udf4d\"",
"sessionStorage[\"\ud800\"]",
"sessionStorage[] = \"\ud800\"",
"sessionStorage[\"\udbff\"]",
"sessionStorage[] = \"\udbff\"",
"sessionStorage[\"\udc00\"]",
"sessionStorage[] = \"\udc00\"",
"sessionStorage[\"\udfff\"]",
"sessionStorage[] = \"\udfff\"",
"sessionStorage[\"\\ufffd\"]",
"sessionStorage[] = \"\\ufffd\"",
"sessionStorage[\"\ud83ca\"]",
"sessionStorage[] = \"\ud83ca\"",
"sessionStorage[\"a\udf4d\"]",
"sessionStorage[] = \"a\udf4d\""
],
"storage_string_conversion.window.html": true,