mpv icon indicating copy to clipboard operation
mpv copied to clipboard

Error parsing watch later files

Open debugzxcv opened this issue 2 years ago • 4 comments

Important Information

Provide following Information:

Reproduction steps

  1. use this script
mp.msg = require("mp.msg")
mp.utils = require("mp.utils")
mp.add_hook("on_preloaded", 50, function()
	local stream_opts = mp.get_property_native("file-local-options/stream-lavf-o")
	mp.msg.warn(mp.utils.to_string(stream_opts))
	stream_opts["cookies"] = "test1=123; path=/; domain=.example.com;\r\ntest2=aaa; path=/; domain=.example.com;\r\n"
	mp.set_property_native("file-local-options/stream-lavf-o", stream_opts)
end)
  1. mpv --save-position-on-quit --watch-later-options-append=stream-lavf-o <FILE>
  2. quit mpv
  3. reopen file on Step 2

Expected behavior

no errors

Actual behavior

watch_later/<MD5>:3: fixed-length quoting expected - put "quotes" around the option value if you did not intend to use this, but your option value starts with '%'
Error parsing option test2 (option not found)
watch_later/<MD5>:4: setting option test2='aaa; path=/; domain=.example.com;' failed.

debugzxcv avatar Dec 02 '23 04:12 debugzxcv

Config files don't support multi-line option values, and that is unlikely to change.

guidocella avatar Dec 02 '23 10:12 guidocella

Config files don't support multi-line option values, and that is unlikely to change.

Is it possible to escape line breaks for multi-line options when saving a watch_later file?

debugzxcv avatar Dec 02 '23 10:12 debugzxcv

If you save \\n that seems to be interpreted as a literal \n in stream-lavf-o. From mpv.conf's documentation: C-style escapes are currently not interpreted on this level, although some options do this manually (this is a mess and should probably be changed at some point)

guidocella avatar Dec 02 '23 11:12 guidocella

This patch works:

diff --git a/options/parse_configfile.c b/options/parse_configfile.c
index edd6be91..a4cc0904 100644
--- a/options/parse_configfile.c
+++ b/options/parse_configfile.c
@@ -105,12 +105,21 @@ int m_config_parse(m_config_t *config, const char *location, bstr data,
                 if (rest.len == line.len || !bstr_eatstart0(&rest, "%") ||
                     len > rest.len)
                 {
+                    if (rest.len && len > rest.len) {
+                        line.len = len + (rest.start - line.start);
+                        rest.len = len;
+                        unsigned char *start = line.start + line.len; 
+                        data.len -= start - data.start;
+                        data.start = start;
+                        goto ok;
+                    }
                     MP_ERR(config, "%s fixed-length quoting expected - put "
                            "\"quotes\" around the option value if you did not "
                            "intend to use this, but your option value starts "
                            "with '%%'\n", loc);
                     goto error;
                 }
+                ok:
                 value = bstr_splice(rest, 0, len);
                 line = bstr_cut(rest, len);
             } else {

debugzxcv avatar Feb 19 '24 18:02 debugzxcv