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.
This commit is contained in:
wm4 2020-01-12 01:04:33 +01:00
parent b947bfcf1f
commit 4b168bcda3
1 changed files with 9 additions and 1 deletions

View File

@ -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 : "<error>");
talloc_free(esc);
talloc_free(s);
}
mp_msg(log, msgl, "]\n");