From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16866 invoked by alias); 15 Dec 2017 02:33:55 -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: 42128 Received: (qmail 23819 invoked by uid 1010); 15 Dec 2017 02:33:55 -0000 X-Qmail-Scanner-Diagnostics: from mail-it0-f50.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(209.85.214.50):SA:0(-1.9/5.0):. Processed in 10.456945 secs); 15 Dec 2017 02:33:55 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_PASS, T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 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=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=RRE4wVGmxhT+C1EQGrwrrV5Ah8PYT77BQb3U8Ws/HJE=; b=GkJ5cnJ3PQrB5WV8Sn0OqsM0TXRpL1PvmsAVNCgKWj6iUvadEJ28FnUomvbXs2FPXj SbM12lgLPMijoNR09L/hLv3QIGEPYyI/7ukHFM+IESJM+kogwjNnSfNZTmyVM/zKUacF v+XUiWA6J0zhETXKVFeO/Fps2RWPi7/rZt14l4PuEZzxM3BTJJpi00krMjeuRd9j+mAI z/2Um5mOyxISwQ3gPxRpt7wnu0yBebOGz8bSqRDx9bcHQcCeNjv15x2N5RkLpl28+jpE fj0n6QdxZYescEOg0CFBI67N7rUz4N779Zvl4miBnEnYTIR0nSyS1KcUWQOYhFPryU4B AasA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=RRE4wVGmxhT+C1EQGrwrrV5Ah8PYT77BQb3U8Ws/HJE=; b=lgsSnuJTI5QQLls/Mf+6THdECeglnSgDPBzreNyRtgRjdkYcffPcclXjCdr65FgrR1 LVRhkXetJzUqYkEnsrmGak7nAFDi+h7uyaPppaitG3zQxwOe2yKksxTCADoD/3NWOr/t tCQr9cJ/HN7d/iM41vRMor6JE/swkqGSZT/3KrW569Odmu5R75RO2WEVGUoYhIOUbcoQ D62/+EEfF7Nw32/o9FkWbhEwrfvhshhnhgki9a7JjBHWEmZ7Be7IgYJNHSsxJBOTJWu4 rHmLRWEX3VfjY8I4IE+9mCVXpcawkuamCFd+iotLTNHjWW1gq3ujnP/BX4InaMfnVOKi +tUw== X-Gm-Message-State: AKGB3mLP5i43EVIPNxFFdyEAgtnQzb93lk655bMz5XH/3ur34wJ7TU4e L6U/bf/hWBlleJtTWE2dsjQftZqjNpM= X-Google-Smtp-Source: ACJfBos913BOaaDfmv6uAB4rXiOLS9M9JhCERHOx2fao/swkN7j9Wnf69fDGn5k+Cjj6W5PR6ZA9hA== X-Received: by 10.107.97.24 with SMTP id v24mr6497213iob.99.1513305221341; Thu, 14 Dec 2017 18:33:41 -0800 (PST) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Subject: Re: [BUG] Strange auto-load behaviour when function name contains hyphen From: dana In-Reply-To: <0110C9C8-53D2-49B4-B0F2-1F3F6A7E6EAC@dana.is> Date: Thu, 14 Dec 2017 20:33:38 -0600 Cc: zsh-workers@zsh.org Content-Transfer-Encoding: quoted-printable Message-Id: <572749ED-05B2-4C68-A931-D83D2FAD58B7@dana.is> References: <990A7EB2-C4BA-4E3D-99B3-7DA40846CBD1@dana.is> <20171214100142.27516153@pwslap01u.europe.root.pri> <20171214102827.78f302fd@pwslap01u.europe.root.pri> <0110C9C8-53D2-49B4-B0F2-1F3F6A7E6EAC@dana.is> To: Peter Stephenson X-Mailer: Apple Mail (2.3273) On 14 Dec 2017, at 11:21, dana wrote: >The patch seems to work for me if i change the condition to this: Understanding a bit more about the token thing, i went and tested some = of the others defined in zsh.h. The same problem occurs if you have a function = name containing almost any of them. Also, if your function name is quoted or = escaped, the tokens for those meta-characters are present and have to be dealt = with for the comparison too. I'm not sure why someone would use an asterisk or whatever in a function = name, but i can't find anything in the documentation that says you shouldn't = (and i'm not aware of any issues doing so aside from this). Should it perform a more comprehensive check? Something like the = following? Possibly it could be optimised to avoid going through the whole dance = when it doesn't need to (considering it's an edge case)... dana diff --git a/Src/exec.c b/Src/exec.c index fc6d02dc3..4c096fd12 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -5932,6 +5932,7 @@ stripkshdef(Eprog prog, char *name) { Wordcode pc; wordcode code; + char *pname, *litpname; =20 if (!prog) return NULL; @@ -5942,10 +5943,25 @@ stripkshdef(Eprog prog, char *name) return prog; pc++; code =3D *pc++; - if (wc_code(code) !=3D WC_FUNCDEF || - *pc !=3D 1 || strcmp(name, ecrawstr(prog, pc + 1, NULL))) + if (wc_code(code) !=3D WC_FUNCDEF || *pc !=3D 1) return prog; =20 + /* + * Detokenise and literalise the name in the word code (it may be = quoted) + * and make sure it matches the expected name + */ + pname =3D ecrawstr(prog, pc + 1, NULL); + litpname =3D ztrdup(pname); + parse_subst_string(litpname); + remnulargs(litpname); + untokenize(litpname); + + if (strcmp(name, litpname)) { + free(litpname); + return prog; + } + free(litpname); + { Eprog ret; Wordcode end =3D pc + WC_FUNCDEF_SKIP(code); diff --git a/Test/C04funcdef.ztst b/Test/C04funcdef.ztst index 0c00a0477..cd29f658c 100644 --- a/Test/C04funcdef.ztst +++ b/Test/C04funcdef.ztst @@ -515,6 +515,22 @@ 0:autoload with absolute path not cancelled by bare autoload >I have been loaded by explicit path. =20 + ( + fpath=3D(.) + print -n '[' + for f in ${(s<>):-'x "#$^*$=3D|`<>?~,-!'}; do + # Test with both backslashes and single-quotes + print -r -- "${(q)f}_1() print -nr -- ${(q)f}" > ${f}_1 + print -r -- "${(qq)f}_2() print -nr -- ${(qq)f}" > ${f}_2 + autoload -Uz -- ${f}_1 ${f}_2 + ${f}_1 + ${f}_2 + done + print ']' + ) +0:autoload with weird function names and ksh-style definitions +>[xx ""##$$^^**$$=3D=3D||``<<>>??~~,,--!!] + ( FUNCNEST=3D0 fn() { true; }