From 4b168bcda3a403fdaeb3696d822f180dd339b929 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 12 Jan 2020 01:04:33 +0100 Subject: input: escape command parameters when logging Some complex commands (like commands generated by scripts to define key bindings or the OSD overlay command) contain new lines, which "corrupts" logging. Fix this by escaping the parameters C-style. Abuse the JSON writer for this, which already has code to vaguely produce C-style escapes. At first I considered stripping the quotes, but then I thought it's actually a good idea to leave them in, as it makes things clearer. Follows an idea by avih. --- input/cmd.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'input') diff --git a/input/cmd.c b/input/cmd.c index 93baa52f43..e9449915f9 100644 --- a/input/cmd.c +++ b/input/cmd.c @@ -25,6 +25,7 @@ #include "cmd.h" #include "input.h" +#include "misc/json.h" #include "libmpv/client.h" @@ -558,7 +559,14 @@ void mp_cmd_dump(struct mp_log *log, int msgl, char *header, struct mp_cmd *cmd) char *s = m_option_print(cmd->args[n].type, &cmd->args[n].v); if (n) mp_msg(log, msgl, ", "); - mp_msg(log, msgl, "%s", s ? s : "(NULL)"); + struct mpv_node node = { + .format = MPV_FORMAT_STRING, + .u.string = s ? s : "(NULL)", + }; + char *esc = NULL; + json_write(&esc, &node); + mp_msg(log, msgl, "%s", esc ? esc : ""); + talloc_free(esc); talloc_free(s); } mp_msg(log, msgl, "]\n"); -- cgit v1.2.3