mirror of
https://github.com/mpv-player/mpv
synced 2025-02-16 12:17:12 +00:00
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:
parent
b947bfcf1f
commit
4b168bcda3
10
input/cmd.c
10
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");
|
||||
|
Loading…
Reference in New Issue
Block a user