original-mawk icon indicating copy to clipboard operation
original-mawk copied to clipboard

mawk mishandles {2,} in regular expressions

Open eggert opened this issue 1 year ago • 3 comments

I found this problem while trying to use mawk to implement tzselect, an awk-using program that's part of tzcode. To reproduce the bug, run this shell command:

mawk 'BEGIN { if ("aaa" ~ /^a{2,}$/) print "ok" }'

This should output "ok" but does not, because the regular expression ^a{2,}$ incorrectly matches only aa.

I found the problem on mawk 1.3.4 20230730 as distributed by Ubuntu 23.10. The problem is still present in mawk 1.3.4 20231126 which I compiled myself.

eggert avatar Dec 09 '23 22:12 eggert

thanks - will fix. I understand the problem, but won't get to this for a few weeks (currently improvements to mawk are behind several other programs).

ThomasDickey avatar Dec 09 '23 23:12 ThomasDickey

mawk 'BEGIN { if ("aaa" ~ /^a{2,5}$/) print "ok" }' fails as well

jlp765 avatar Dec 28 '23 03:12 jlp765

This doesn't look right either.

$ echo 'x xx ' | mawk '{sub(/(x+ +){2}/, "y")} 1'
yxx

oguz-ismail avatar Mar 07 '24 17:03 oguz-ismail