From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id e46d3262 for ; Mon, 31 Dec 2018 16:23:33 +0000 (UTC) Received: (qmail 10939 invoked by alias); 31 Dec 2018 16:23:19 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 43964 Received: (qmail 1444 invoked by uid 1010); 31 Dec 2018 16:23:18 -0000 X-Qmail-Scanner-Diagnostics: from mail-it1-f195.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.100.2/25112. spamassassin: 3.4.2. Clear:RC:0(209.85.166.195):SA:0(-1.9/5.0):. Processed in 5.380419 secs); 31 Dec 2018 16:23:18 -0000 X-Envelope-From: dana@dana.is X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | 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:date:references :to:in-reply-to:message-id; bh=MvGOvC3A9U8G97rN3bX+jLLDcqexzlUwdqemClnXCTI=; b=ciosNiEK9z2VC5BUmb5MAOxKj/ZvmJy2kvgsLEYvqD8sUdqYRV/XpHnvGvU4IQTpTq 9RX2eeu4sg0+P8zCL96/NqPEjFwgwBPDIdnS6/S4SPlIaHlySXtoTkl6MAIC7wxdsUoe iHgQ0SOGJGFclJXLjX0l+1E4gEtQLzbrai6EUMJi2gx6TuBtuL5eUAFZcf8KcEFEjJqF Pr92JzLqhuwKuUnDD3il3EMAz6yzlfTuCiXfL722uvNDRSVbN8tlyq7tdPsJ0fqe1JHd 5gE/GTKBOTDknWpdkciYXhlvxjQAnhNAwW6IJP8zspEWlYsYZnJqw71Ws2EE/RP63E0l 6VqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:content-transfer-encoding:mime-version :subject:date:references:to:in-reply-to:message-id; bh=MvGOvC3A9U8G97rN3bX+jLLDcqexzlUwdqemClnXCTI=; b=s853ySdRuNVqxNC34qhbvZG9rvV8gvriZM46MYXC3PNoJaAkj1MMqQzLRfOYIj093B r0JiyP7FYQRgs9LePyk0JLJtcYNH74NwkYRP8jkpa3GkcqP0Gl1Yfi2Dp37YkxWlAF0w uqx0ipm+WuCfGwXQjlTnZLJ5+yTR551ZAyUtj1cXHI1et6laN15aIqNALSdy0ev1quwn FAP9ekpdeTlB6NTQpE5hTwKhehjbwXFZ6xyRuV0fjngibwbNyThwLRazbMEsH38lvkls FaG1h/CVXmIy1Siyj1uQghRZ9YtMMyOMt4WvFwwn7t5M/RbTmf7bcNfJ/WZSgCFepOkV nkmw== X-Gm-Message-State: AA+aEWaP0LswoKCIghe4bfFrugE6Q6IQwKjZVdTKQtk2zZ5nmCCvmaeS bceP2+RsCkV/INcaKGQHeWoV2DgL5af9EQ== X-Google-Smtp-Source: AFSGD/WJeXri78DdvWG+Auo9+y0sm9i31jAq4WdE2mUwuXy+rxtcrMTclAXVFwZRtHD0Rbr3qnj3AA== X-Received: by 2002:a02:7e95:: with SMTP id g21mr23437722jae.114.1546273390066; Mon, 31 Dec 2018 08:23:10 -0800 (PST) From: dana Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 12.0 \(3445.100.39\)) Subject: Re: [PATCH] computil: Fix inconsistent handling of slash-escaped option names Date: Mon, 31 Dec 2018 10:25:33 -0600 References: To: Zsh workers In-Reply-To: Message-Id: <111E6C9B-71D3-4558-8E03-E7FF92E655EE@dana.is> X-Mailer: Apple Mail (2.3445.100.39) On 21 Dec 2018, at 03:41, dana wrote: >Unless i'm missing something, this seems to fix it... It does, but it also breaks some behaviour that _describe relies on. Specifically, it expects comparguments to return the \ escape sequences = as-is, and it doesn't do that any more now that i'm unescaping everything. The real-world consequences of this are not very noticeable, since = _arguments and _describe don't handle option names containing : and \ well anyway. = I decided it's probably not worth trying to fix that. But i didn't want to = leave anything worse than i found it, so here's a v2 patch. It simply changes bslashcolon() =E2=80=94 which is pretty much only used = to re-escape option names for _describe =E2=80=94 to also re-escape \. That should at = least keep the status quo. I thought about renaming the function to = bslashbslashcolon(), but that felt kind of extra, so i didn't. (Aside from that i also expanded some comments and tests, and removed a rembslashcolon() that i'd forgot before) dana diff --git a/Src/Zle/computil.c b/Src/Zle/computil.c index cb1c01042..b54e62aec 100644 --- a/Src/Zle/computil.c +++ b/Src/Zle/computil.c @@ -1060,7 +1060,8 @@ rembslashcolon(char *s) return r; } =20 -/* Add backslashes before colons. */ +/* Add backslashes before backslashes and colons. This is suitable for = e.g. + * re-escaping option names to pass back to _describe. */ =20 static char * bslashcolon(char *s) @@ -1070,7 +1071,7 @@ bslashcolon(char *s) r =3D p =3D zhalloc((2 * strlen(s)) + 1); =20 while (*s) { - if (*s =3D=3D ':') + if (*s =3D=3D '\\' || *s =3D=3D ':') *p++ =3D '\\'; *p++ =3D *s++; } @@ -1402,14 +1403,19 @@ parse_cadef(char *nam, char **args) return NULL; } =20 - /* Skip over the name. */ + /* Skip over the name, unescaping to support unusual option = names + * like -+ and -=3D as described in zshcompsys(1). Note that = other + * parts of the completion system have their own = considerations for + * certain special characters; for example, the option -: = may pose + * issues for utility functions which expect : to introduce = a + * description. */ for (p++; *p && *p !=3D ':' && *p !=3D '[' && ((*p !=3D '-' && *p !=3D '+') || (p[1] !=3D ':' && p[1] !=3D '[')) && (*p !=3D '=3D' || (p[1] !=3D ':' && p[1] !=3D '[' && p[1] !=3D = '-')); p++) if (*p =3D=3D '\\' && p[1]) - p++; + chuck(p); =20 /* The character after the option name specifies the type. = */ c =3D *p; @@ -1455,7 +1461,7 @@ parse_cadef(char *nam, char **args) xor[0] =3D xor[1] =3D NULL; } zsfree(xor[xnum]); - xor[xnum] =3D ztrdup(rembslashcolon(name)); + xor[xnum] =3D ztrdup(name); } if (c =3D=3D ':') { /* There's at least one argument. */ @@ -1527,7 +1533,7 @@ parse_cadef(char *nam, char **args) =20 opt->next =3D NULL; opt->gsname =3D doset; - opt->name =3D ztrdup(rembslashcolon(name)); + opt->name =3D ztrdup(name); if (descr) opt->descr =3D ztrdup(descr); else if (adpre && oargs && !oargs->next) { diff --git a/Test/Y03arguments.ztst b/Test/Y03arguments.ztst index fa4589374..4761e47a3 100644 --- a/Test/Y03arguments.ztst +++ b/Test/Y03arguments.ztst @@ -78,11 +78,28 @@ >line: {tst rest arg2 }{} >line: {tst rest arg2 rest }{} =20 - tst_arguments '-\+[opt]' + # We test -+ and -=3D here as they are documented to work when = escaped. Other + # options containing special characters, like -: and -\, are currently + # problematic for various reasons (though they would probably pass = this basic + # check) + tst_arguments -s : '-\+[opt1]' '-\=3D[opt2]' '-a[opt3]' '-b[opt4]' comptest $'tst -\C-d' -0:-+ ->DESCRIPTION:{option} ->NO:{-+ -- opt} + comptest $'tst -+\C-d' + comptest $'tst -=3D\C-d' +0:slash-escaped option name (-+, -=3D) +>DESCRIPTION:{option} +>NO:{-+ -- opt1} +>NO:{-=3D -- opt2} +>NO:{-a -- opt3} +>NO:{-b -- opt4} +>DESCRIPTION:{option} +>NO:{-=3D -- opt2} +>NO:{-a -- opt3} +>NO:{-b -- opt4} +>DESCRIPTION:{option} +>NO:{-+ -- opt1} +>NO:{-a -- opt3} +>NO:{-b -- opt4} =20 tst_arguments -+o comptest $'tst -\t\t\t\C-w\C-w+\t\t\t'