diff options
Diffstat (limited to 'op_crates/url')
-rw-r--r-- | op_crates/url/00_url.js | 11 | ||||
-rw-r--r-- | op_crates/url/Cargo.toml | 1 | ||||
-rw-r--r-- | op_crates/url/internal.d.ts | 1 | ||||
-rw-r--r-- | op_crates/url/lib.rs | 21 |
4 files changed, 27 insertions, 7 deletions
diff --git a/op_crates/url/00_url.js b/op_crates/url/00_url.js index 7c24a871a..f51b4aedc 100644 --- a/op_crates/url/00_url.js +++ b/op_crates/url/00_url.js @@ -391,8 +391,19 @@ } } + /** + * This function implements application/x-www-form-urlencoded parsing. + * https://url.spec.whatwg.org/#concept-urlencoded-parser + * @param {Uint8Array} bytes + * @returns {[string, string][]} + */ + function parseUrlEncoded(bytes) { + return core.opSync("op_url_parse_search_params", null, bytes); + } + window.__bootstrap.url = { URL, URLSearchParams, + parseUrlEncoded, }; })(this); diff --git a/op_crates/url/Cargo.toml b/op_crates/url/Cargo.toml index ab3ac9e1d..a67b59d7f 100644 --- a/op_crates/url/Cargo.toml +++ b/op_crates/url/Cargo.toml @@ -16,6 +16,7 @@ path = "lib.rs" [dependencies] deno_core = { version = "0.84.0", path = "../../core" } idna = "0.2.2" +percent-encoding = "2.1.0" serde = { version = "1.0.125", features = ["derive"] } [dev-dependencies] diff --git a/op_crates/url/internal.d.ts b/op_crates/url/internal.d.ts index f852928d3..ec2c2688c 100644 --- a/op_crates/url/internal.d.ts +++ b/op_crates/url/internal.d.ts @@ -8,6 +8,7 @@ declare namespace globalThis { declare var url: { URL: typeof URL; URLSearchParams: typeof URLSearchParams; + parseUrlEncoded(bytes: Uint8Array): [string, string][]; }; } } 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<ZeroCopyBuf>, + args: Option<String>, + zero_copy: Option<ZeroCopyBuf>, ) -> Result<Vec<(String, String)>, 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( |