zsh-workers
 help / color / mirror / code / Atom feed
From: Stephane Chazelas <stephane.chazelas@gmail.com>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: zsh-workers@zsh.org
Subject: Re: [PATCH] PCRE/NUL: pass NUL in for text, handle NUL out
Date: Sat, 17 Jun 2017 07:31:28 +0100	[thread overview]
Message-ID: <20170617063128.GA5478@chaz.gmail.com> (raw)
In-Reply-To: <170616201049.ZM28016@torch.brasslantern.com>

2017-06-16 20:10:49 -0700, Bart Schaefer:
> On Jun 16,  7:41am, Stephane Chazelas wrote:
> }
> } Solution for now in zsh is to escape like:
> } 
> }    [[ $x =~ "\b\Q${word//\\E/\\E\\\\E\\Q}\E" ]]
> 
> Hmm, wouldn't "\b\Q${(b)word}\E" be sufficient there?  In fact if
> you've applied ${(b)word} do you even need \E and \Q ?

Not really

Inside \Q...\E PCREs, only \E is special, and there's no
escaping you may do. It's like strong quotes. Changing ? to \?
would change the meaning of the regexp. And wouldn't help for \E

Outside of \Q...\E where what needs to be escaped on whether the
regexp has a (?x)), there are things like . or $ (or blanks with
(?x)) it would still leave unescaped.

PCREs (as opposed to some ERE implementations that have things
like \<, \=) are good though in that AFAICT, there are only \x
operators where x is an ASCII alnum, so adding a \ in front of
every ASCII non-alnum should be enough I would think (as long as
we're not inside [...] or things like \g{...}). So a an
equivalent of ${(b)var} for PCRE should not too difficult.

Quoting both ERE and PCRE is a problem in theory for (?x) and
blanks where "\ " is unspecified in ERE, but in practice, I
don't think any ERE implementation would ever have "\ " as a
special operator. So I think it should be a matter of quoting
only (and not more than):

ASCII [[:space:]]
$^*()+[]{}.?\|

(and again (from a security standpoint at least), that quoting
could be fooled in some locales like those that have BIG5-HKSCS
or GB18030 as the charset where some characters whose encoding
contains the encoding of other characters including ASCII ones).

-- 
Stephane


  reply	other threads:[~2017-06-17  6:31 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
2017-06-17  3:10     ` Bart Schaefer
2017-06-17  6:31       ` Stephane Chazelas [this message]
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=20170617063128.GA5478@chaz.gmail.com \
    --to=stephane.chazelas@gmail.com \
    --cc=schaefer@brasslantern.com \
    --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).