Bug 198552 - [patch] awk unmatched right parenthesis in regular expressions
Summary: [patch] awk unmatched right parenthesis in regular expressions
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 9.3-RELEASE
Hardware: Any Any
: --- Affects Many People
Assignee: freebsd-bugs (Nobody)
URL:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2015-03-12 22:08 UTC by Nathan Weeks
Modified: 2021-07-09 17:40 UTC (History)
1 user (show)

See Also:


Attachments
Patch to awk 20121220 b.c (993 bytes, patch)
2015-03-12 22:08 UTC, Nathan Weeks
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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
http://weeks.public.iastate.edu/
Comment 1 Pedro F. Giffuni freebsd_committer freebsd_triage 2017-10-08 04:43:32 UTC
Another one for Warner...
Comment 2 Warner Losh freebsd_committer freebsd_triage 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.
Comment 3 Warner Losh freebsd_committer freebsd_triage 2021-07-09 17:40:39 UTC
This was fixed when f39dd6a9784467f0db5886012b3f4b13899be6b8 was imported.