From 24fffa0f6b053695ddd09122f79cd5b185a7082c Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 14 Oct 2013 21:04:45 +0200 Subject: mplayer: escape strings if needed when writing watch_later config This fixes handling of e.g. "--vf=lavfi=[ noise ]" when used with playback resume functionality. The spaces made it bug out, and there are more cases where it could potentially break. We could always escape for simplicity, but for now make old and new mpv builds somewhat interoperable and use this new escaping only if needed. --- mpvcore/mplayer.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/mpvcore/mplayer.c b/mpvcore/mplayer.c index 6800f84a7f..c0504caf5f 100644 --- a/mpvcore/mplayer.c +++ b/mpvcore/mplayer.c @@ -860,6 +860,17 @@ static const char *backup_properties[] = { 0 }; +// Should follow what parser-cfg.c does/needs +static bool needs_config_quoting(const char *s) +{ + for (int i = 0; s && s[i]; i++) { + unsigned char c = s[i]; + if (!isprint(c) || isspace(c) || c == '#' || c == '\'' || c == '"') + return true; + } + return false; +} + void mp_write_watch_later_conf(struct MPContext *mpctx) { void *tmp = talloc_new(NULL); @@ -889,8 +900,14 @@ void mp_write_watch_later_conf(struct MPContext *mpctx) const char *pname = backup_properties[i]; char *val = NULL; int r = mp_property_do(pname, M_PROPERTY_GET_STRING, &val, mpctx); - if (r == M_PROPERTY_OK) - fprintf(file, "%s=%s\n", pname, val); + if (r == M_PROPERTY_OK) { + if (needs_config_quoting(val)) { + // e.g. '%6%STRING' + fprintf(file, "%s=%%%d%%%s\n", pname, (int)strlen(val), val); + } else { + fprintf(file, "%s=%s\n", pname, val); + } + } talloc_free(val); } fclose(file); -- cgit v1.2.3