PulseAudio Marge Bot pushed to branch master at PulseAudio / pulseaudio
Commits: 8262815e by Igor V. Kovalenko at 2021-10-19T09:45:27+03:00 message-params: If message paremeters is not JSON, wrap into JSON string Requiring user to invoke send-message with correctly quoted parameters string is not good for usability. Wrap parameters string into JSON string and try again. If that works, log a warning use wrapped JSON string with parameters. As an example these two commands will now invoke the same action: pactl send-message /card/bluez_card... switch-codec '"CODECNAME"' pactl send-message /card/bluez_card... switch-codec CODECNAME Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/648> - - - - - 1 changed file: - src/pulsecore/message-handler.c Changes: ===================================== src/pulsecore/message-handler.c ===================================== @@ -131,8 +131,26 @@ int pa_message_handler_send_message(pa_core *c, const char *object_path, const c if (message_parameters) { parameters = pa_json_parse(message_parameters); - if (!parameters) - return -PA_ERR_INVALID; + if (!parameters) { + char *wrapped_message_parameters; + + /* Message parameters is not a valid JSON + * + * Wrap message parameters into JSON string and try again. + * User might have missed double-quotes and passed ARGSTRING instead of proper JSON "ARGSTRING" + */ + pa_log_warn(_("Message parameters is not a valid JSON, wrapping into JSON string '\"%s\"'"), message_parameters); + + wrapped_message_parameters = pa_sprintf_malloc("\"%s\"", message_parameters); + parameters = pa_json_parse(wrapped_message_parameters); + pa_xfree(wrapped_message_parameters); + + if (!parameters) { + pa_log_error(_("Message parameters is not a valid JSON object. Tried both '%s' and '\"%s\"'"), + message_parameters, message_parameters); + return -PA_ERR_INVALID; + } + } } /* The handler is expected to return an error code and may also View it on GitLab: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/commit/8262815e94aa6716c20ba9a3f2737e5dd5e4adad -- View it on GitLab: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/commit/8262815e94aa6716c20ba9a3f2737e5dd5e4adad You're receiving this email because of your account on gitlab.freedesktop.org.