Skip to content

Commit

Permalink
wasm: blob url support
Browse files Browse the repository at this point in the history
  • Loading branch information
skyf0l committed Apr 10, 2023
1 parent 7047669 commit 36b4b9a
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/into_url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ pub trait IntoUrlSealed {

impl IntoUrlSealed for Url {
fn into_url(self) -> crate::Result<Url> {
#[cfg(target_arch = "wasm32")]
if self.scheme() == "blob"
&& self.path().starts_with("http")
&& self.as_str()[5..].into_url().is_ok()
{
return Ok(self);
}

if self.has_host() {
Ok(self)
} else {
Expand Down Expand Up @@ -87,4 +95,24 @@ mod tests {
"builder error for url (file:///etc/hosts): URL scheme is not allowed"
);
}

#[test]
fn into_url_blob_scheme() {
let err = "blob:https://example.com".into_url().unwrap_err();
assert_eq!(
err.to_string(),
"builder error for url (blob:https://example.com): URL scheme is not allowed"
);
}

if_wasm! {
use wasm_bindgen_test::*;

#[wasm_bindgen_test]
fn into_url_blob_scheme_wasm() {
let url = "blob:http://example.com".into_url().unwrap();

assert_eq!(url.as_str(), "blob:http://example.com");
}
}
}

0 comments on commit 36b4b9a

Please sign in to comment.