[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-gawk] escaping open curly bracket produces unexpected warning w
From: |
arnold |
Subject: |
Re: [bug-gawk] escaping open curly bracket produces unexpected warning with --posix |
Date: |
Wed, 19 Jun 2019 13:24:40 -0600 |
User-agent: |
Heirloom mailx 12.5 7/5/10 |
Hi.
Ed Morton <address@hidden> wrote:
> I just came across this in gawk 5.0.0 (note "4"):
>
> 1) $ echo 'foo{bar' | awk '/{/'
> foo{bar
>
> 2) $ echo 'foo{bar' | awk --posix '/{/'
> awk: cmd. line:1: error: Invalid preceding regular expression: /{/
>
> 3) $ echo 'foo{bar' | awk '/\{/'
> foo{bar
>
> 4) $ echo 'foo{bar' | awk --posix '/\{/'
> awk: cmd. line:1: warning: regexp escape sequence `\{' is not a
> known regexp operator
> foo{bar
>
> I understand 1, 2, and 3 but I don't understand why I get the warning
> from 4 above. I expected `\{` to simply be treated as a literal `{` with
> no warnings just like other RE metachars are:
>
> $ echo 'foo[bar' | awk --posix '/\[/'
> foo[bar
>
> $ echo 'foo+bar' | awk --posix '/\+/'
> foo+bar
>
> Instead I had to put it inside square brackets to get it treated as
> literal with no warnings:
>
> $ echo 'foo{bar' | awk --posix '/[{]/'
> foo{bar
>
> as no amount of additional preceding backslashes would make it "work"
> without a warning:
>
> $ echo 'foo{bar' | awk --posix '/\{/'
> awk: cmd. line:1: warning: regexp escape sequence `\{' is not a
> known regexp operator
> foo{bar
> $ echo 'foo{bar' | awk --posix '/\\{/'
> $ echo 'foo{bar' | awk --posix '/\\\{/'
> awk: cmd. line:1: warning: regexp escape sequence `\{' is not a
> known regexp operator
> $ echo 'foo{bar' | awk --posix '/\\\\{/'
> $
>
> Regards,
>
> Ed.
The patch below fixes this.
Thanks for the report.
Arnold
-----------------------------------------------------------------
diff --git a/re.c b/re.c
index 174f54f8..210be068 100644
--- a/re.c
+++ b/re.c
@@ -107,7 +107,9 @@ make_regexp(const char *s, size_t len, bool ignorecase,
bool dfa, bool canfatal)
}
const char *ok_to_escape;
- if (do_traditional)
+ if (do_posix)
+ ok_to_escape = "{}()|*+?.^$\\[]/-";
+ else if (do_traditional)
ok_to_escape = "()|*+?.^$\\[]/-";
else
ok_to_escape = "<>`'BywWsS{}()|*+?.^$\\[]/-";