From 9e6cd91014ac4a0d34556b0d09cbe25e4e0930c6 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Tue, 20 Apr 2021 14:47:22 +0200 Subject: chore: align fetch to spec (#10203) This commit aligns the `fetch` API and the `Request` / `Response` classes belonging to it to the spec. This commit enables all the relevant `fetch` WPT tests. Spec compliance is now at around 90%. Performance is essentially identical now (within 1% of 1.9.0). --- op_crates/url/lib.rs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'op_crates/url/lib.rs') diff --git a/op_crates/url/lib.rs b/op_crates/url/lib.rs index f216768c3..04663e411 100644 --- a/op_crates/url/lib.rs +++ b/op_crates/url/lib.rs @@ -118,14 +118,21 @@ pub fn op_url_parse( pub fn op_url_parse_search_params( _state: &mut deno_core::OpState, - args: String, - _zero_copy: Option, + args: Option, + zero_copy: Option, ) -> Result, AnyError> { - let search_params: Vec<_> = form_urlencoded::parse(args.as_bytes()) - .into_iter() - .map(|(k, v)| (k.as_ref().to_owned(), v.as_ref().to_owned())) - .collect(); - Ok(search_params) + let params = match (args, zero_copy) { + (None, Some(zero_copy)) => form_urlencoded::parse(&zero_copy) + .into_iter() + .map(|(k, v)| (k.as_ref().to_owned(), v.as_ref().to_owned())) + .collect(), + (Some(args), None) => form_urlencoded::parse(args.as_bytes()) + .into_iter() + .map(|(k, v)| (k.as_ref().to_owned(), v.as_ref().to_owned())) + .collect(), + _ => return Err(type_error("invalid parameters")), + }; + Ok(params) } pub fn op_url_stringify_search_params( -- cgit v1.2.3