From b9b2eb16d446667ca09ca5972769169f01e4ba19 Mon Sep 17 00:00:00 2001 From: "Sam A. Horvath-Hunt" Date: Tue, 11 Jun 2019 17:39:39 +0100 Subject: [PATCH] Fix native messaging to check bytes length instead of string length --- src/native_messaging.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/native_messaging.rs b/src/native_messaging.rs index bae9001..d3b7250 100644 --- a/src/native_messaging.rs +++ b/src/native_messaging.rs @@ -49,7 +49,7 @@ pub fn read_input(mut input: R) -> Result { /// Chrome's documentation on native messaging. /// (https://developer.chrome.com/extensions/nativeMessaging#native-messaging-host-protocol) pub fn write_output(mut output: W, val: &JSON) -> Result { - 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 @@ -61,7 +61,7 @@ pub fn write_output(mut output: W, val: &JSON) -> Result(len as u32) .map_err(|_| NativeMessagingError::UnknownFailure)?; output - .write_all(msg.as_bytes()) + .write_all(msg.as_slice()) .map_err(|_| NativeMessagingError::UnknownFailure)?; output .flush()