diff options
author | Denys Vlasenko | 2023-06-03 00:39:33 +0200 |
---|---|---|
committer | Denys Vlasenko | 2023-06-03 00:42:10 +0200 |
commit | 5f84c5633663f6ee8c9cc3a4608b86d4b56b39d6 (patch) | |
tree | f3c3aa3267164310b55192a1a3b174523aa49dbe /testsuite | |
parent | 0256e00a9d077588bd3a39f5a1ef7e2eaa2911e4 (diff) | |
download | busybox-5f84c5633663f6ee8c9cc3a4608b86d4b56b39d6.zip busybox-5f84c5633663f6ee8c9cc3a4608b86d4b56b39d6.tar.gz |
awk: fix backslash handling in sub() builtins
function old new delta
awk_sub 559 544 -15
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'testsuite')
-rwxr-xr-x | testsuite/awk.tests | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/testsuite/awk.tests b/testsuite/awk.tests index cdab93d..c61d329 100755 --- a/testsuite/awk.tests +++ b/testsuite/awk.tests @@ -552,4 +552,51 @@ testing "awk = has higher precedence than == (despite what gawk manpage claims)" '0\n1\n2\n1\n3\n' \ '' '' +sq="'" +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. +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 +' \ + '' '' + exit $FAILCOUNT |