Skip to content

Commit

Permalink
fix(android): do not crash on custom protocol handler if URL is inval…
Browse files Browse the repository at this point in the history
…id (#1332)
  • Loading branch information
lucasfernog authored Aug 6, 2024
1 parent 5231a37 commit 19d83d7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changes/fix-android-crash-custom-protocol.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wry": patch
---

Fixes a crash on the Android custom protocol handler when the request URL is invalid.
18 changes: 9 additions & 9 deletions src/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,21 +203,21 @@ impl InnerWebView {
REQUEST_HANDLER.get_or_init(move || {
UnsafeRequestHandler::new(Box::new(
move |mut request, is_document_start_script_enabled| {
let uri = request.uri().to_string();
if let Some(custom_protocol) = custom_protocols.iter().find(|(name, _)| {
request
.uri()
.to_string()
.starts_with(&format!("{scheme}://{}.", name))
uri.starts_with(&format!("{scheme}://{}.", name))
}) {
*request.uri_mut() = request
.uri()
.to_string()
let uri_res = uri
.replace(
&format!("{scheme}://{}.", custom_protocol.0),
&format!("{}://", custom_protocol.0),
)
.parse()
.unwrap();
.parse();
println!("{:?} {:?}", request.uri(), uri_res);

if let Ok(uri) = uri_res {
*request.uri_mut() = uri;
}

let (tx, rx) = channel();
let initialization_scripts = initialization_scripts.clone();
Expand Down

0 comments on commit 19d83d7

Please sign in to comment.