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

Re: [BUG] Strange auto-load behaviour when function name contains hyphen



On Thu, 14 Dec 2017 00:46:29 -0600
dana <dana@xxxxxxx> wrote:
> The documentation states that function files intended for zsh-style
> auto-loading are allowed to contain a 'simple definition' (`foo() {
> ... }`) if that's the only thing in the file. This seems to work
> fine... except when the function name contains a hyphen.

A while back we had to turn "-" into a token to fix a compatibility
issue with pattern matching in POSIX shells.  This has caused problems
to come out of the wardrobe ever since.  ("Woodwork" implies a level
of solid material without the appropriate magical connotations.)

This has got line offsets including the function line numbering change as it
currently stands but I won't commit that.

pws

diff --git a/Src/exec.c b/Src/exec.c
index fc6d02d..5149349 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -5932,6 +5934,7 @@ stripkshdef(Eprog prog, char *name)
 {
     Wordcode pc;
     wordcode code;
+    char *ptr1, *ptr2;
 
     if (!prog)
 	return NULL;
@@ -5942,8 +5945,23 @@ stripkshdef(Eprog prog, char *name)
 	return prog;
     pc++;
     code = *pc++;
-    if (wc_code(code) != WC_FUNCDEF ||
-	*pc != 1 || strcmp(name, ecrawstr(prog, pc + 1, NULL)))
+    if (wc_code(code) != WC_FUNCDEF ||	*pc != 1)
+	return prog;
+
+    /*
+     * See if name of function requested (name) is same as
+     * name of function in word code.  name may still have "-"
+     * tokenised.
+     */
+    ptr1 = name;
+    ptr2 = ecrawstr(prog, pc + 1, NULL);
+    while (*ptr1 && *ptr2) {
+	if (*ptr1 != *ptr2 && *ptr1 != Dash && *ptr1 != '-')
+	    break;
+	ptr1++;
+	ptr2++;
+    }
+    if (*ptr1 || *ptr2)
 	return prog;
 
     {



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