[Bug 12531] New: awk: backslashes not parsed in EREs passed from variables or "string literals"

bugzilla at busybox.net bugzilla at busybox.net
Mon Feb 3 21:12:15 UTC 2020


https://bugs.busybox.net/show_bug.cgi?id=12531

            Bug ID: 12531
           Summary: awk: backslashes not parsed in EREs passed from
                    variables or "string literals"
           Product: Busybox
           Version: unspecified
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P5
         Component: Standard Compliance
          Assignee: unassigned at busybox.net
          Reporter: martijn at inlv.org
                CC: busybox-cvs at busybox.net
  Target Milestone: ---

Created attachment 8356
  --> https://bugs.busybox.net/attachment.cgi?id=8356&action=edit
my .config, as required

In busybox awk, match(), sub() and gsub() don't parse C-style backslash-escaped
special characters in EREs passed from variables or "string literals" (as
opposed to /ERE literals/, for which busybox awk behaves correctly).

Below are a couple of test cases. (Note: double quotes remove one level of
backslash escaping; the ERE parsing in match(), sub(), gsub() should be
removing another)


$ echo $'abc\tdef' | awk '{ ere="\\t"; gsub(ere, "TAB"); print; }'
abc     def

Expected output (as on onetrueawk, gawk, mawk, Solaris awk):
abcTABdef


$ awk 'BEGIN { print !match("\n", "^\\n$"); }'
1

Expected output (as on onetrueawk, gawk, mawk, Solaris awk):
0

Reference to standard:
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/awk.html#tag_20_06_13_04

Regular Expressions: ..."The awk utility shall make use of the extended regular
expression notation (see XBD Extended Regular Expressions) except that it shall
allow the use of C-language conventions for escaping special characters within
the EREs, as specified in the table in XBD File Format Notation ( '\\', '\a',
'\b', '\f' , '\n', '\r', '\t', '\v' ) and the following table; these escape
sequences shall be recognized both inside and outside bracket expressions."...

RATIONALE: ..."Historical implementations of awk have long supported
<backslash>-escape sequences as an extension to extended regular expressions,
and this extension has been retained despite inconsistency with other
utilities."...

-- 
You are receiving this mail because:
You are on the CC list for the bug.


More information about the busybox-cvs mailing list