Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(macos): crash when custom protocol response is empty #567

Merged
merged 1 commit into from May 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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