mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-03-16 10:10:52 +00:00
bindings for decodeURIComponent
This commit is contained in:
parent
f850a6fafc
commit
0f07dd9048
@ -49,6 +49,13 @@ extern "C" {
|
||||
#[wasm_bindgen(catch, js_name = decodeURI)]
|
||||
pub fn decode_uri(encoded: &str) -> Result<JsString, JsValue>;
|
||||
|
||||
/// The decodeURIComponent() function decodes a Uniform Resource Identifier (URI)
|
||||
/// component previously created by encodeURIComponent or by a similar routine.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURIComponent
|
||||
#[wasm_bindgen(catch, js_name = decodeURIComponent)]
|
||||
pub fn decode_uri_component(encoded: &str) -> Result<JsString, JsValue>;
|
||||
|
||||
/// The `encodeURI()` function encodes a Uniform Resource Identifier (URI)
|
||||
/// by replacing each instance of certain characters by one, two, three, or
|
||||
/// four escape sequences representing the UTF-8 encoding of the character
|
||||
|
@ -6,8 +6,8 @@ mod Array;
|
||||
mod ArrayIterator;
|
||||
mod Boolean;
|
||||
mod Date;
|
||||
mod Function;
|
||||
mod Error;
|
||||
mod Function;
|
||||
mod JsString;
|
||||
mod Map;
|
||||
mod MapIterator;
|
||||
@ -47,6 +47,32 @@ fn decode_uri() {
|
||||
.test();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn decode_uri_component() {
|
||||
project()
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(proc_macro, wasm_custom_section)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::js;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn test() {
|
||||
let x = js::decode_uri_component("%3Fx%3Dtest")
|
||||
.ok()
|
||||
.expect("should decode URI OK");
|
||||
assert_eq!(String::from(x), "?x=test");
|
||||
|
||||
assert!(js::decode_uri_component("%E0%A4%A").is_err());
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "std")]
|
||||
fn encode_uri() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user