From: Phil Pennock <zsh-workers+phil.pennock@spodhuis.org>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: Zsh hackers list <zsh-workers@zsh.org>
Subject: [PATCH] repair conds where - within cond name
Date: Thu, 10 Aug 2017 22:02:46 -0400 [thread overview]
Message-ID: <20170811020246.GA718@breadbox.private.spodhuis.org> (raw)
In-Reply-To: <CAH+w=7bQYtBo1PbNYpyU9ToWndB7BvMkSoGd2M=XrmqQ1toWiA@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2737 bytes --]
On 2017-08-10 at 18:49 -0700, Bart Schaefer wrote:
> On Aug 10, 2017 6:37 PM, "Phil Pennock" <
> zsh-workers+phil.pennock@spodhuis.org> wrote:
>
> 40760: Always tokenize unquoted - to Dash.
>
> I remember this, and thought there was a subsequent patch that fixed it
> again.
Not in master.
Fix below; adds a test too. Did I really not provide tests for the
zsh/regex module? :(
-Phil
From 6f0dcb270ff13327fef341974a1dde4e9a7a4f86 Mon Sep 17 00:00:00 2001
From: Phil Pennock <phil@pennock-tech.com>
Subject: [PATCH] repair conds where - within cond name
Date: Thu, 10 Aug 2017 21:58:11 -0400
In 40760 we switched to tokenizing `-` to `Dash` broadly; the condtab
lookup is a simple strcmp but some of the loadable conditionals have a
`-` within their name (-regex-match and -pcre-match). That failed.
De-tokenize this one character before lookup.
Add a test-case.
---
Src/module.c | 17 +++++++++++++++--
Test/V07pcre.ztst | 9 +++++++++
2 files changed, 24 insertions(+), 2 deletions(-)
diff --git a/Src/module.c b/Src/module.c
index 21d68b1ac..b5f522bf0 100644
--- a/Src/module.c
+++ b/Src/module.c
@@ -649,11 +649,21 @@ getconddef(int inf, const char *name, int autol)
{
Conddef p;
int f = 1;
+ char *lookup, *s;
+
+ /* detokenize the Dash to the form encoded in lookup tables */
+ lookup = ztrdup(name);
+ if (!lookup)
+ return NULL;
+ for (s = lookup; *s != '\0'; s++) {
+ if (*s == Dash)
+ *s = '-';
+ }
do {
for (p = condtab; p; p = p->next) {
if ((!!inf == !!(p->flags & CONDF_INFIX)) &&
- !strcmp(name, p->name))
+ !strcmp(lookup, p->name))
break;
}
if (autol && p && p->module) {
@@ -664,16 +674,19 @@ getconddef(int inf, const char *name, int autol)
if (f) {
(void)ensurefeature(p->module,
(p->flags & CONDF_INFIX) ? "C:" : "c:",
- (p->flags & CONDF_AUTOALL) ? NULL : name);
+ (p->flags & CONDF_AUTOALL) ? NULL : lookup);
f = 0;
p = NULL;
} else {
deleteconddef(p);
+ free(lookup);
return NULL;
}
} else
break;
} while (!p);
+
+ free(lookup);
return p;
}
diff --git a/Test/V07pcre.ztst b/Test/V07pcre.ztst
index 7426e7bf8..ab41d33dc 100644
--- a/Test/V07pcre.ztst
+++ b/Test/V07pcre.ztst
@@ -137,6 +137,15 @@
0:ensure ASCII NUL passes in and out of matched plaintext
>6; 3; 3
+# Ensure the long-form infix operator works
+ [[ foo -pcre-match ^f..$ ]]
+ print $?
+ [[ foo -pcre-match ^g..$ ]]
+ print $?
+0:infix -pcre-match works
+>0
+>1
+
# Subshell because crash on failure
( setopt re_match_pcre
[[ test.txt =~ '^(.*_)?(test)' ]]
--
2.14.1
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 996 bytes --]
next prev parent reply other threads:[~2017-08-11 2:02 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <86221c7e-aa71-28a7-21c2-8ed800090edd@bureaucracy.de>
[not found] ` <20170811010701.GA94571@tower.spodhuis.org>
2017-08-11 1:36 ` -pcre-match doesn't work since version 5.4.1 Phil Pennock
2017-08-11 1:49 ` Bart Schaefer
2017-08-11 2:02 ` Phil Pennock [this message]
2017-08-11 8:31 ` [PATCH] repair conds where - within cond name Peter Stephenson
2017-08-11 17:18 ` Phil Pennock
2017-08-11 18:45 ` Daniel Shahaf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170811020246.GA718@breadbox.private.spodhuis.org \
--to=zsh-workers+phil.pennock@spodhuis.org \
--cc=schaefer@brasslantern.com \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).