| 1 |
#!/bin/sh |
| 2 |
|
| 3 |
awk="$AWK -v BINMODE=2" |
| 4 |
SED="sed -e '/^\$/d' -e 's/[ ][ ]*/ /g' -e 's/ *\$//'" |
| 5 |
|
| 6 |
# Both of these succeeded: |
| 7 |
# export LC_CTYPE=C |
| 8 |
export LC_CTYPE="en_US.UTF-8" |
| 9 |
|
| 10 |
|
| 11 |
# Test terminal backslash handling. Each test should produce "5c 0a" |
| 12 |
# (a backslash followed by a newline). Presently, master produces "0a". |
| 13 |
# |
| 14 |
$awk -F'\' 'BEGIN { print FS }' | od -An -tx1 | eval $SED |
| 15 |
$awk -v s='\' 'BEGIN { print s }' | od -An -tx1 | eval $SED |
| 16 |
echo | $awk '{ print s }' s='\' | od -An -tx1 | eval $SED |
| 17 |
|
| 18 |
|
| 19 |
# These are the same terminal backslash handling tests we just ran, but |
| 20 |
# with a line-continuation pair immediately preceding the terminal |
| 21 |
# backslash. Let's make sure these two special sequences play well. |
| 22 |
# Their output should be the same as before, "5c 0a". Again, master |
| 23 |
# produces only "0a". The backslash is lost. |
| 24 |
# |
| 25 |
$awk -F'\ |
| 26 |
\' 'BEGIN { print FS }' | od -An -tx1 | eval $SED |
| 27 |
$awk -v s='\ |
| 28 |
\' 'BEGIN { print s }' | od -An -tx1 | eval $SED |
| 29 |
echo | $awk '{ print s }' s='\ |
| 30 |
\' | od -An -tx1 | eval $SED |
| 31 |
|
| 32 |
|
| 33 |
# \uffffffff (-1) |
| 34 |
# \ufffffffe (-2) |
| 35 |
# |
| 36 |
# A properly handled invalid \u sequence yields a literal '?' (3f). |
| 37 |
# This test should print "3f 0a 3f 0a", but master prints "5c 0a 5c 0a". |
| 38 |
# |
| 39 |
# The code point overflows parse_escape's int return value, yielding one |
| 40 |
# of the reserved, negative values. In this case, make_str_node is |
| 41 |
# confused into preserving a terminal backslash that doesn't exist. |
| 42 |
# |
| 43 |
$awk 'BEGIN { |
| 44 |
print "\uFFFFFFFF" # "?\n" |
| 45 |
print "\uFFFFFFFE" # "?\n" |
| 46 |
}' | od -An -tx1 | eval $SED # 3f 0a 3f 0a |
| 47 |
|
| 48 |
|
| 49 |
# Again, a negative return value causes confusion, this time producing a |
| 50 |
# fatal error in make_regexp. |
| 51 |
# |
| 52 |
$awk 'BEGIN { |
| 53 |
if ("xy?z" ~ /xy\uFFFFFFFFz/) |
| 54 |
print "right: literal ? is literal" |
| 55 |
else |
| 56 |
print "wrong: literal ? is meta" |
| 57 |
}' |
| 58 |
|
| 59 |
# \uD800 to \uDFFF are invalid Unicode code points. They're reserved |
| 60 |
# for UTF-16 surrogates. Let's use them to test \u conversion error |
| 61 |
# handling. The correct output is a true expression, 0 == 0 or 1 == 1. |
| 62 |
# |
| 63 |
$awk 'BEGIN { |
| 64 |
print "1 == " ("xy?z" ~ /xy\uD800z/) |
| 65 |
print "1 == " ("xy?z" ~ "xy\\uD800z") |
| 66 |
|
| 67 |
print "0 == " ("xyz" ~ /xy\uD800z/) |
| 68 |
print "0 == " ("xyz" ~ "xy\\uD800z") |
| 69 |
|
| 70 |
print "0 == " ("xz" ~ /xy\uD800z/) |
| 71 |
print "0 == " ("xz" ~ "xy\\uD800z") |
| 72 |
}' |
| 73 |
|
| 74 |
exit 0 |