diff options
author | Denys Vlasenko | 2023-06-08 10:42:39 +0200 |
---|---|---|
committer | Denys Vlasenko | 2023-06-08 10:42:39 +0200 |
commit | 2ca39ffd447ca874fcea933194829717d5573247 (patch) | |
tree | 6d9eb4ba80ad9feec70c3f4f25dd3f7629c5fe5a /testsuite | |
parent | 113685fbcd4c3432ec9b640583d50ba8da2102e8 (diff) | |
download | busybox-2ca39ffd447ca874fcea933194829717d5573247.zip busybox-2ca39ffd447ca874fcea933194829717d5573247.tar.gz |
awk: fix subst code to handle "start of word" pattern correctly (needs REG_STARTEND)
function old new delta
awk_sub 637 714 +77
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'testsuite')
-rwxr-xr-x | testsuite/awk.tests | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/testsuite/awk.tests b/testsuite/awk.tests index c61d329..5a792c2 100755 --- a/testsuite/awk.tests +++ b/testsuite/awk.tests @@ -557,14 +557,12 @@ testing 'awk gensub backslashes \' \ 'awk '$sq'BEGIN { s="\\"; print "s=" s; print gensub("a", s, "g", "a|a") }'$sq \ 's=\\ \\|\\ -' \ - '' '' +' '' '' testing 'awk gensub backslashes \\' \ 'awk '$sq'BEGIN { s="\\\\"; print "s=" s; print gensub("a", s, "g", "a|a") }'$sq \ 's=\\\\ \\|\\ -' \ - '' '' +' '' '' # gawk 5.1.1 handles trailing unpaired \ inconsistently. # If replace string is single \, it is used verbatim, # but if it is \\\ (three slashes), gawk uses "\<NUL>" (!!!), not "\\" as you would expect. @@ -572,31 +570,35 @@ testing 'awk gensub backslashes \\\' \ 'awk '$sq'BEGIN { s="\\\\\\"; print "s=" s; print gensub("a", s, "g", "a|a") }'$sq \ 's=\\\\\\ \\\\|\\\\ -' \ - '' '' +' '' '' testing 'awk gensub backslashes \\\\' \ 'awk '$sq'BEGIN { s="\\\\\\\\"; print "s=" s; print gensub("a", s, "g", "a|a") }'$sq \ 's=\\\\\\\\ \\\\|\\\\ -' \ - '' '' +' '' '' testing 'awk gensub backslashes \&' \ 'awk '$sq'BEGIN { s="\\&"; print "s=" s; print gensub("a", s, "g", "a|a") }'$sq \ 's=\\& &|& -' \ - '' '' +' '' '' testing 'awk gensub backslashes \0' \ 'awk '$sq'BEGIN { s="\\0"; print "s=" s; print gensub("a", s, "g", "a|a") }'$sq \ 's=\\0 a|a -' \ - '' '' +' '' '' testing 'awk gensub backslashes \\0' \ 'awk '$sq'BEGIN { s="\\\\0"; print "s=" s; print gensub("a", s, "g", "a|a") }'$sq \ 's=\\\\0 \\0|\\0 -' \ +' '' '' + +# The "b" in "abc" should not match <b* pattern. +# Currently we use REG_STARTEND ("This flag is a BSD extension, not present in POSIX") +# to implement the code to handle this correctly, but if your libc has no REG_STARTEND, +# the alternative code mishandles this case. +testing 'awk gsub erroneous word start match' \ + "awk 'BEGIN { a=\"abc\"; gsub(/\<b*/,\"\",a); print a }'" \ + 'abc\n' \ '' '' exit $FAILCOUNT |