zsh-workers
 help / color / mirror / code / Atom feed
From: Stephane Chazelas <stephane.chazelas@gmail.com>
To: Phil Pennock <zsh-workers+phil.pennock@spodhuis.org>
Cc: zsh-workers@zsh.org
Subject: Re: [PATCH] PCRE/NUL: pass NUL in for text, handle NUL out
Date: Fri, 16 Jun 2017 07:41:29 +0100	[thread overview]
Message-ID: <20170616064129.GA19469@chaz.gmail.com> (raw)
In-Reply-To: <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


  reply	other threads:[~2017-06-16  6:41 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20170615204203epcas5p4b0a2bcbcfe0843d979c653df6b8352db@epcas5p4.samsung.com>
2017-06-15 20:40 ` Phil Pennock
2017-06-16  6:41   ` Stephane Chazelas [this message]
2017-06-17  3:10     ` Bart Schaefer
2017-06-17  6:31       ` Stephane Chazelas
2017-06-20 20:07   ` Phil Pennock
2017-06-21  8:59   ` Peter Stephenson
2017-06-21 22:48     ` Phil Pennock

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 \
    --in-reply-to=20170616064129.GA19469@chaz.gmail.com \
    --to=stephane.chazelas@gmail.com \
    --cc=zsh-workers+phil.pennock@spodhuis.org \
    --cc=zsh-workers@zsh.org \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

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).