bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-gawk] escaping open curly bracket produces unexpected warning w


From: Ed Morton
Subject: Re: [bug-gawk] escaping open curly bracket produces unexpected warning with --posix
Date: Wed, 19 Jun 2019 15:16:53 -0500
User-agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.7.1

Arnold - great, thanks for the quick turn-around.

    Ed.

On 6/19/2019 2:24 PM, address@hidden wrote:
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{}()|*+?.^$\\[]/-";




reply via email to

[Prev in Thread] Current Thread [Next in Thread]