summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2020-01-12 01:04:33 +0100
committerwm4 <wm4@nowhere>2020-01-12 01:04:33 +0100
commit4b168bcda3a403fdaeb3696d822f180dd339b929 (patch)
tree3184aa8a84e4b1d32c023d74f8dadbc9e1ef4e66
parentb947bfcf1f17f42745168863d5ade3acc1b02f9c (diff)
downloadmpv-4b168bcda3a403fdaeb3696d822f180dd339b929.tar.bz2
mpv-4b168bcda3a403fdaeb3696d822f180dd339b929.tar.xz
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.
-rw-r--r--input/cmd.c10
1 files changed, 9 insertions, 1 deletions
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 : "<error>");
+ talloc_free(esc);
talloc_free(s);
}
mp_msg(log, msgl, "]\n");