Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[PATCH] computil: Fix inconsistent handling of slash-escaped option names
- X-seq: zsh-workers 43922
- From: dana <dana@xxxxxxx>
- To: Zsh workers <zsh-workers@xxxxxxx>
- Subject: [PATCH] computil: Fix inconsistent handling of slash-escaped option names
- Date: Fri, 21 Dec 2018 03:41:21 -0600
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dana-is.20150623.gappssmtp.com; s=20150623; h=from:content-transfer-encoding:mime-version:subject:message-id:date :to; bh=ZlrHFoLm8eJFSBkIT5jtezeXkFcvLgpsT7zWsxbmByI=; b=EdMUh9dtxx1+Kj3xske5bOg+m0CCWPyD1lQY8zrJisfXeDRtJxSDOsh7a2ksvU0wu/ QmKvQFF7hHiF7PIGq3Etn1BdPVTuN6ZAbPLwZTIbz8Ym6VG6ksnWr1w1pm04O30fIVh9 pBa7IBvvFvbw+aEE2BA316VDTJ3Fp6oqWOWeV08GBGdxNgT7gFGIQ7ecs/IZABaEApG9 R6hlWuu4/fUkE8/9HEylaOvZQf9USYnHYLyP3l1WqEMc6SG3HQJyqbANx/+8VTGBAlXC Ecyd5FSyreMLoyF6fN0cuUti40ZyWMA2eBnejFLWcEjFQsyZp6zJvBnCsUp2wHXfsXId D8uw==
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
When writing option specs, you're supposed to be able to escape characters in
the option name that are special to the syntax; as the manual says:
>It is possible for options with a literal ‘+’ or ‘=’ to appear, but that
>character must be quoted, for example ‘-\+’.
This sort of works, but not entirely. It does make the name valid, and the
option does appear correctly as a possibility, but because the slashes are
only skipped when parsing, not actually removed from the final name, the
completion system gets confused when you actually use it. For example:
% _foo() { _arguments -s : '-\+' -a -b }
% compdef _foo foo
% foo -+<TAB>
Because of the -s, it should try to complete -a or -b in the same word.
Instead, it starts a new word, and it behaves as if -+ hasn't been used yet.
Unless i'm missing something, this seems to fix it...
dana
diff --git a/Src/Zle/computil.c b/Src/Zle/computil.c
index cb1c01042..a98574379 100644
--- a/Src/Zle/computil.c
+++ b/Src/Zle/computil.c
@@ -1409,7 +1409,7 @@ parse_cadef(char *nam, char **args)
(*p != '=' ||
(p[1] != ':' && p[1] != '[' && p[1] != '-')); p++)
if (*p == '\\' && p[1])
- p++;
+ chuck(p);
/* The character after the option name specifies the type. */
c = *p;
@@ -1527,7 +1527,7 @@ parse_cadef(char *nam, char **args)
opt->next = NULL;
opt->gsname = doset;
- opt->name = ztrdup(rembslashcolon(name));
+ opt->name = ztrdup(name);
if (descr)
opt->descr = ztrdup(descr);
else if (adpre && oargs && !oargs->next) {
diff --git a/Test/Y03arguments.ztst b/Test/Y03arguments.ztst
index fa4589374..ec9fd9e8a 100644
--- a/Test/Y03arguments.ztst
+++ b/Test/Y03arguments.ztst
@@ -78,11 +78,17 @@
>line: {tst rest arg2 }{}
>line: {tst rest arg2 rest }{}
- tst_arguments '-\+[opt]'
+ tst_arguments -s : '-\+[opt1]' '-a[opt2]' '-b[opt3]'
comptest $'tst -\C-d'
-0:-+
+ comptest $'tst -+\C-d'
+0:slash-escaped option name (-+)
>DESCRIPTION:{option}
->NO:{-+ -- opt}
+>NO:{-+ -- opt1}
+>NO:{-a -- opt2}
+>NO:{-b -- opt3}
+>DESCRIPTION:{option}
+>NO:{-a -- opt2}
+>NO:{-b -- opt3}
tst_arguments -+o
comptest $'tst -\t\t\t\C-w\C-w+\t\t\t'
Messages sorted by:
Reverse Date,
Date,
Thread,
Author