summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-10-14 21:04:45 +0200
committerwm4 <wm4@nowhere>2013-10-14 21:05:58 +0200
commit24fffa0f6b053695ddd09122f79cd5b185a7082c (patch)
treee094351273298721fd72e7d013f6b19c9bf1ebf5
parent5106edfd5e1b57a39a5121266b61dcc657c4aff6 (diff)
downloadmpv-24fffa0f6b053695ddd09122f79cd5b185a7082c.tar.bz2
mpv-24fffa0f6b053695ddd09122f79cd5b185a7082c.tar.xz
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.
-rw-r--r--mpvcore/mplayer.c21
1 files 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);