Skip to content
This repository has been archived by the owner on Sep 7, 2024. It is now read-only.

Commit

Permalink
Fix native messaging to check bytes length instead of string length
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam A. Horvath-Hunt committed Jun 11, 2019
1 parent fed7e58 commit b9b2eb1
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/native_messaging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub fn read_input<R: Read>(mut input: R) -> Result<JSON, NativeMessagingError> {
/// Chrome's documentation on native messaging.
/// (https://developer.chrome.com/extensions/nativeMessaging#native-messaging-host-protocol)
pub fn write_output<W: Write>(mut output: W, val: &JSON) -> Result<W, NativeMessagingError> {
let msg = serde_json::to_string(val).map_err(|_| NativeMessagingError::UnknownFailure)?;
let msg = serde_json::to_vec(val).map_err(|_| NativeMessagingError::UnknownFailure)?;
let len = msg.len();

// Web browsers won't accept a message larger than 1MB
Expand All @@ -61,7 +61,7 @@ pub fn write_output<W: Write>(mut output: W, val: &JSON) -> Result<W, NativeMess
.write_u32::<NativeEndian>(len as u32)
.map_err(|_| NativeMessagingError::UnknownFailure)?;
output
.write_all(msg.as_bytes())
.write_all(msg.as_slice())
.map_err(|_| NativeMessagingError::UnknownFailure)?;
output
.flush()
Expand Down

0 comments on commit b9b2eb1

Please sign in to comment.