nih-plug-webview icon indicating copy to clipboard operation
nih-plug-webview copied to clipboard

Fix: Fix send_json cannot send message with some specific characters

Open sevenc-nanashi opened this issue 1 year ago • 2 comments

This library couldn't send messages with some specific characters such as:

  • backquotes
  • \" sequence

This PR fixes the problem by changing the way to send json. While original used backquotes to send JSON string, this PR uses serde_json twice to do so.

sevenc-nanashi avatar Sep 30 '24 12:09 sevenc-nanashi

This is not related to the PR, but: serde_json::Value implements Display trait, which returns JSON of the value: https://docs.rs/serde_json/latest/serde_json/enum.Value.html#impl-Display-for-Value In other words, there is a infailable implementation of serde_json::Value to JSON converter.

By the existence of this method, and the source of Deserialize implementation, serde_json::to_string(Value) looks infallible, thus the else branch looks unreachable.

sevenc-nanashi avatar Sep 30 '24 13:09 sevenc-nanashi

@sevenc-nanashi thanks for this, LGTM!

your reasoning about the else branch being unnecessary seems solid too; you could include its removal in this PR on my behalf.

httnn avatar Oct 07 '24 14:10 httnn

I made it use to_string(). This method no longer Errs, but I keep it return Result in order not to break backward compatibility.

sevenc-nanashi avatar Oct 09 '24 10:10 sevenc-nanashi

thanks a lot! merging now

httnn avatar Oct 09 '24 14:10 httnn

FYI: made send_json() not return a Result anymore. also noted it in the readme.

httnn avatar Oct 09 '24 14:10 httnn