Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH] PCRE/NUL: pass NUL in for text, handle NUL out
- X-seq: zsh-workers 41309
- From: Stephane Chazelas <stephane.chazelas@xxxxxxxxx>
- To: Phil Pennock <zsh-workers+phil.pennock@xxxxxxxxxxxx>
- Subject: Re: [PATCH] PCRE/NUL: pass NUL in for text, handle NUL out
- Date: Fri, 16 Jun 2017 07:41:29 +0100
- Cc: zsh-workers@xxxxxxx
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to:user-agent; bh=S1OKYR5H8QYl9gfBcz2153ZUdI129VLPqOdyUqM/+Nc=; b=r9p9btkLjCwmpvQ1TdtufYfM+fuCnyqcASOAGtN90BJcxLEFFsHxMeCywZP098prLs tnMdPska82rUB4v9gJ3VotIHYDGUy5e5EODfF9DX4MephWKTdPaDA0GZVNZvG8Ixtqbc TcvyY9FQ4Zw5IvigSubOvUhKbosQKcphSyMXy1MQlxTlR3qz7M4YZCWV7Blg/mfeCTOL YWWfPsK3t9dsskpopxqnFJQNWYSwbX+waq/kYLKtbeueWc7nXMb9KqQ747XPGydmLmbj Fu8GXFaN7mcQ39DYE+EdJO7v6P7UBbDkdN6geKVthl/5ej+PCdsaeJFBxGKm17qVIqgn 5Qow==
- In-reply-to: <20170615204050.GA27003@breadbox.private.spodhuis.org>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mail-followup-to: Phil Pennock <zsh-workers+phil.pennock@xxxxxxxxxxxx>, zsh-workers@xxxxxxx
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <20170615204050.GA27003@breadbox.private.spodhuis.org>
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
himself.
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).
--
Stephane
Messages sorted by:
Reverse Date,
Date,
Thread,
Author