Bug 198552

Summary: [patch] awk unmatched right parenthesis in regular expressions
Product: Base System Reporter: Nathan Weeks <nathan.weeks>
Component: binAssignee: freebsd-bugs (Nobody) <bugs>
Status: New ---    
Severity: Affects Many People CC: imp
Priority: --- Keywords: patch
Version: 9.3-RELEASE   
Hardware: Any   
OS: Any   
Description Flags
Patch to awk 20121220 b.c none

Description Nathan Weeks 2015-03-12 22:08:44 UTC
Created attachment 154253 [details]
Patch to awk 20121220 b.c

awk version 20121220 disallows the use of an unmatched right parenthesis in regular expressions:

$ awk 'BEGIN { print match("...)", ")") }'
awk: illegal primary in regular expression ) at
 source line number 1
 context is
        BEGIN { print match("...)", >>>  ")") <<<

The unmatched right parenthesis should be allowed in this context, as POSIX.1-2008 (http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html#tag_09_04_03) states the following in section 9.4.3 (ERE Special Characters):

"The <right-parenthesis> shall be special when matched with a preceding <left-parenthesis>, both outside a bracket expression."

and in section 9.5.1 (BRE/ERE Grammar Lexical Conventions) (http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html#tag_09_05_01), the description of the "SPEC_CHAR" token contains the following exception:

"The close-parenthesis shall be considered special in this context only if matched with a preceding open-parenthesis."

I contacted Mr. BWK, who agreed that it was a bug. I then attempted to fix it using the attached patch, which I submitted to BWK, but didn't get a response. Consequently, don't have high hopes for this issue being fixed upstream, but I'm submitting this bug report so that it is documented somewhere.

Nathan Weeks
IT Specialist
USDA-ARS Corn Insects and Crop Genetics Research Unit
Crop Genome Informatics Laboratory
Iowa State University
Comment 1 Pedro F. Giffuni freebsd_committer 2017-10-08 04:43:32 UTC
Another one for Warner...
Comment 2 Warner Losh freebsd_committer 2019-06-03 06:29:21 UTC
upstream one true awk has been integrated into FreeBSD. As such, this no longer applies. If I apply by hand, I get a significant number of regressions in the awk test suite.