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

Re: [PATCH] PCRE/NUL: pass NUL in for text, handle NUL out

2017-06-15 16:40:50 -0400, Phil Pennock:
> The regexp itself is always NUL-terminated, so detect embedded NULs and
> zwarn on their presence.

Thanks Phil.

Maybe an improvement could be to replace those NULs with a
litteral \0. Though that would not be valid if the NUL is
preceded by a backslash or within \Q...\E. So it's probably
just as well to use the warning to let the user do the escaping

Having a way to use \Q...\E reliably would be nice by the way

As in a variant of:

    [[ $x =~ "...\Q$y\E" ]]

That still works if $y contains \E. (I can't think of a
reasonable way though).

bash32+/ksh93 support:

    [[ $x =~ ..."$y"...]]

as in quoting $y prevents interpretation of RE operators in
them. It's quite buggy in ksh93, and in bash, that means the
syntax is limited to POSIX ERE even on systems where EREs have
many extensions like  \<, back-references... (except if you
store the regex in a variable which you then leave unquoted:
ws='\<' we='\>'; [[ $var = $ws"$word"$we ]], not [[ $var =
\<"$word"\> ]]) so I'm not sure we want to go there.

Solution for now in zsh is to escape like:

   [[ $x =~ "\b\Q${word//\\E/\\E\\\\E\\Q}\E" ]]

(possibly still doesn't work in locales that have characters
whose encoding ends in 0x5c bytes (same as \), but nobody should
use those really in this day and age).


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