Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

[PATCH] repair conds where - within cond name



On 2017-08-10 at 18:49 -0700, Bart Schaefer wrote:
> On Aug 10, 2017 6:37 PM, "Phil Pennock" <
> zsh-workers+phil.pennock@xxxxxxxxxxxx> 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@xxxxxxxxxxxxxxxx>
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: signature.asc
Description: Digital signature



Messages sorted by: Reverse Date, Date, Thread, Author