diff options
author | Avi Halachmi (:avih) <avihpit@yahoo.com> | 2021-07-28 12:29:08 +0300 |
---|---|---|
committer | avih <avih@users.noreply.github.com> | 2021-07-30 09:52:34 +0300 |
commit | 9f6cbf3a4d0b994f0ab42d59479f48cc7b4f8923 (patch) | |
tree | e2a5009e20874988fe1af1bf619da5d8359bc292 /input | |
parent | 73c9509720e59aec059e206506c0cf461d635c9f (diff) | |
download | mpv-9f6cbf3a4d0b994f0ab42d59479f48cc7b4f8923.tar.bz2 mpv-9f6cbf3a4d0b994f0ab42d59479f48cc7b4f8923.tar.xz |
input: arguments quoting: support single-quotes
Users expect single quotes to work when the value includes literal
backslashes or double-quotes (or as general quoting like in shell).
The updated docs also include some previously-missing notes:
- newline is only supported in double quotes.
- adjacent (quoted) arguments don't join into one.
Supporting mixed quoting (adjacent quoted strings) would make
mpv's parsing more complete, but would require delicate effort of
larger scope, for two reasons:
- We'd need to also support escaping outside of quotes and do our
best about backward compatibility.
- The parsed value can either be a substring of the input or
a newly-allocated string, which would be delicate when joining.
Not critical to add right now.
Diffstat (limited to 'input')
-rw-r--r-- | input/cmd.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/input/cmd.c b/input/cmd.c index 9f0c758b0c..0ab06e3574 100644 --- a/input/cmd.c +++ b/input/cmd.c @@ -336,11 +336,21 @@ static int pctx_read_token(struct parse_ctx *ctx, bstr *out) return -1; } if (!bstr_eatstart0(&ctx->str, "\"")) { - MP_ERR(ctx, "Unterminated quotes: ...>%.*s<.\n", BSTR_P(start)); + MP_ERR(ctx, "Unterminated double quote: ...>%.*s<.\n", BSTR_P(start)); return -1; } return 1; } + if (bstr_eatstart0(&ctx->str, "'")) { + int next = bstrchr(ctx->str, '\''); + if (next < 0) { + MP_ERR(ctx, "Unterminated single quote: ...>%.*s<.\n", BSTR_P(start)); + return -1; + } + *out = bstr_splice(ctx->str, 0, next); + ctx->str = bstr_cut(ctx->str, next+1); + return 1; + } if (ctx->start.len > 1 && bstr_eatstart0(&ctx->str, "`")) { char endquote[2] = {ctx->str.start[0], '`'}; ctx->str = bstr_cut(ctx->str, 1); |