From ea5db5090c775ac00bb6dd83a0704dad44b66f7f Mon Sep 17 00:00:00 2001 From: Andy C Date: Mon, 25 Nov 2024 18:36:59 -0500 Subject: [PATCH] [spec/word-split] Add failing test case for IFS bug #2141 --- devtools/refactor.sh | 12 ++++++++++-- spec/word-split.test.sh | 39 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/devtools/refactor.sh b/devtools/refactor.sh index 3997d89201..306ce40433 100755 --- a/devtools/refactor.sh +++ b/devtools/refactor.sh @@ -279,9 +279,17 @@ test-files() { # singleton-list() { - egrep -n '\(List\[[^]]+\] [a-z]+\)' */*.asdl + egrep -n '\(List\[[^]]+\] [a-z_]+\)' */*.asdl + echo + egrep -n '\(Dict\[[^]]+\] [a-z_]+\)' */*.asdl +} + +singleton-primitive() { + egrep -n '\(str [a-z_]+\)' */*.asdl + echo + + egrep -n '\(int [a-z_]+\)' */*.asdl echo - egrep -n '\(Dict\[[^]]+\] [a-z]+\)' */*.asdl } task-five "$@" diff --git a/spec/word-split.test.sh b/spec/word-split.test.sh index 3075eb430e..454537a02b 100644 --- a/spec/word-split.test.sh +++ b/spec/word-split.test.sh @@ -1,5 +1,5 @@ ## compare_shells: bash dash mksh -## oils_failures_allowed: 8 +## oils_failures_allowed: 9 # NOTE on bash bug: After setting IFS to array, it never splits anymore? Even # if you assign IFS again. @@ -419,3 +419,40 @@ noglob ['[\\]_'] ## END + +#### Empty IFS bug #2141 (from pnut) + +res=0 +sum() { + # implement callee-save calling convention using `set` + # here, we save the value of $res after the function parameters + set $@ $res # $1 $2 $3 are now set + res=$(($1 + $2)) + echo "$1 + $2 = $res" + res=$3 # restore the value of $res +} + +unset IFS +sum 12 30 # outputs "12 + 30 = 42" + +IFS=' ' +sum 12 30 # outputs "12 + 30 = 42" + +IFS= +sum 12 30 # outputs "1230 + 0 = 1230" + +# I added this +IFS='' +sum 12 30 + +set -u +IFS= +sum 12 30 # fails with "fatal: Undefined variable '2'" on res=$(($1 + $2)) + +## STDOUT: +12 + 30 = 42 +12 + 30 = 42 +12 + 30 = 42 +12 + 30 = 42 +12 + 30 = 42 +## END