Skip to content

Commit

Permalink
fix(macos): crash when custom protocol response is empty (#567)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed May 2, 2022
1 parent a5ddb5c commit 67809f4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changes/fix-macos-protocol-crash.md
@@ -0,0 +1,5 @@
---
"wry": patch
---

Fixes a crash when the custom protocol response is empty on macOS.
5 changes: 2 additions & 3 deletions src/webview/wkwebview/mod.rs
Expand Up @@ -11,7 +11,7 @@ pub use web_context::WebContextImpl;
#[cfg(target_os = "macos")]
use cocoa::appkit::{NSView, NSViewHeightSizable, NSViewWidthSizable};
use cocoa::{
base::{id, nil, YES},
base::{id, nil, NO, YES},
foundation::{NSDictionary, NSFastEnumeration, NSInteger},
};

Expand Down Expand Up @@ -183,8 +183,7 @@ impl InnerWebView {
// Send data
let bytes = content.as_ptr() as *mut c_void;
let data: id = msg_send![class!(NSData), alloc];
let data: id =
msg_send![data, initWithBytesNoCopy:bytes length:content.len() freeWhenDone: YES];
let data: id = msg_send![data, initWithBytesNoCopy:bytes length:content.len() freeWhenDone: if content.len() == 0 { NO } else { YES }];
let () = msg_send![task, didReceiveData: data];
} else {
let urlresponse: id = msg_send![class!(NSHTTPURLResponse), alloc];
Expand Down

0 comments on commit 67809f4

Please sign in to comment.