nih-plug-webview
nih-plug-webview copied to clipboard
Fix: Fix send_json cannot send message with some specific characters
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.
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 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.
I made it use to_string().
This method no longer Errs, but I keep it return Result in order not to break backward compatibility.
thanks a lot! merging now
FYI: made send_json() not return a Result anymore. also noted it in the readme.