From eb56186e4499c7584d2cfffdca4fde7ad3da16ee Mon Sep 17 00:00:00 2001 From: Aaron O'Mullan Date: Wed, 19 May 2021 20:45:48 +0200 Subject: [PATCH] fix(serde_v8): remove intentional deserialization error on non-utf8 strings (#10156) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bartek Iwańczuk --- serde_v8/src/de.rs | 18 +----------------- tools/wpt/expectation.json | 30 ++---------------------------- 2 files changed, 3 insertions(+), 45 deletions(-) diff --git a/serde_v8/src/de.rs b/serde_v8/src/de.rs index f351d78709..b0237d514a 100644 --- a/serde_v8/src/de.rs +++ b/serde_v8/src/de.rs @@ -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` in rusty-v8 let v8_string = v8::Local::::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, -) -> Option { - let string = s.to_rust_string_lossy(scope); - match string.find(std::char::REPLACEMENT_CHARACTER) { - Some(_) => None, - None => Some(string), - } -} diff --git a/tools/wpt/expectation.json b/tools/wpt/expectation.json index afdc0cb1f4..4d6016104e 100644 --- a/tools/wpt/expectation.json +++ b/tools/wpt/expectation.json @@ -683,8 +683,6 @@ "Stringification of new URLSearchParams(\"hi=there&thank=you\")" ], "url-constructor.any.html": [ - "Parsing: against ", - "Parsing: against ", "Parsing: against ", "Parsing: against ", "Parsing: against ", @@ -740,10 +738,7 @@ "Parsing: <> against ", "Parsing: against " ], - "url-origin.any.html": [ - "Origin parsing: against ", - "Origin parsing: against " - ], + "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: �=x&&�=a", - "URL parse and sort: �=x&&�=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,