From: Eric Blake <firstname.lastname@example.org> To: Stephane Chazelas <email@example.com> Cc: Herbert Xu <firstname.lastname@example.org>, Harald van Dijk <email@example.com>, firstname.lastname@example.org, email@example.com Subject: Re: [v2 PATCH] expand: Always quote caret when using fnmatch Date: Mon, 21 Feb 2022 10:39:08 -0600 [thread overview] Message-ID: <firstname.lastname@example.org> (raw) In-Reply-To: <email@example.com> On Sun, Feb 20, 2022 at 07:15:44AM +0000, Stephane Chazelas wrote: > 2022-01-19 16:37:54 +1100, Herbert Xu: > [...] > > This patch forces ^ to be a literal when we use fnmatch. > [...] > The "fix" also seems incomplete and causes at least this > regression: > > $ ltrace -e fnmatch ./bin/dash -c 'case "\\" in ($1) echo match; esac' sh '[\^]' > dash->fnmatch("[\\\\^]", "\\", 0) = 0 > match > > See how that added \ caused it to be included in the set. Compare with: > > +++ exited (status 0) +++ > $ ltrace -e fnmatch ./bin/dash -c 'case "\\" in ($1) echo match; esac' sh '[\!]' > dash->fnmatch("[\\!]", "\\", 0) = 1 > +++ exited (status 0) +++ > $ ltrace -e fnmatch ./bin/dash -c 'case "\\" in ($1) echo match; esac' sh '[\x]' > dash->fnmatch("[\\x]", "\\", 0) = 1 > +++ exited (status 0) +++ If you want to escape ^ to always be treated as a literal when calling fnmatch(), you have to spell it something like [[=^=]...], not [\^...] (that is, since \^ inside  does NOT treat the \ as an escape character, but as yet another literal character as part of the brakcet group, you instead have to resort to calling out the literal character ^ via alternative spellings such as by a collation equivalent). Another alternative is to rewrite the  bracket exprsesion so that ^ is no longer first (but be careful if the character after ^ is -, ], or !, as the rewrite is not always a trivial swap with the next character). -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
next prev parent reply other threads:[~2022-02-21 16:41 UTC|newest] Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-01-12 16:25 possible wrong behaviour with patterns using a quoted ^ at the start of a bracket expression Christoph Anton Mitterer 2022-01-12 17:20 ` Harald van Dijk 2022-01-12 17:47 ` Christoph Anton Mitterer 2022-01-12 18:17 ` Harald van Dijk 2022-01-12 18:21 ` Christoph Anton Mitterer 2022-01-18 6:13 ` [PATCH] expand: Always quote caret when using fnmatch Herbert Xu 2022-01-18 8:44 ` Harald van Dijk 2022-01-19 5:37 ` [v2 PATCH] " Herbert Xu 2022-02-20 7:15 ` Stephane Chazelas 2022-02-21 16:39 ` Eric Blake [this message] 2022-02-21 17:06 ` Harald van Dijk 2022-02-21 19:15 ` Stephane Chazelas 2022-01-18 14:29 ` [PATCH] " Christoph Anton Mitterer 2022-01-18 14:54 ` Chet Ramey 2022-01-18 22:33 ` Herbert Xu
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 \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --subject='Re: [v2 PATCH] expand: Always quote caret when using fnmatch' \ /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
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).