Subject: Re: bug#26409: plus (`+`) not a metacharacter with --posix option, escaped or not

From: Assaf Gordon <[email-masked]>
Date: Sun, 9 Apr 2017 13:36:37 -0400

Hello,

> On Apr 8, 2017, at 20:37, Jordan Torbiak <[email-masked]> wrote:
> 
> The plus character can't seem to be used as a metacharacter when both the
> `-E` and `--posix` options are given.
> [...]
> $ echo 'hi+' | sed --posix -E 's/(.+)/{\1}/'
> h{i+}

Thank you for the report.

I can confirm this is reproducible.

I think the cause is that '--posix' sets the sed variable
'posixicity=POSIXLY_BASIC' and then all regex are compiled
with the  RE_LIMITED_OPS option which disables +/?/| .

[1] regex options in sed:
    https://git.savannah.gnu.org/cgit/sed.git/tree/sed/regexp.c#n90
[2] gnulib RE_LIMITED_OPS:
    https://git.savannah.gnu.org/cgit/gnulib.git/tree/lib/regex.h#n134

regarding POSIX compliance - this sounds like it needs to be fixed,
but I'm not an export - perhaps others can chime in ?

I think a simple 'if extended_regexp_flags & REG_EXTENDED' inside
the 'switch (posixicity)' can fix this. I can send a patch a bit later.

regards,
 - assaf