NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

PR/60099 CVS commit: src/tests/bin/sh



The following reply was made to PR bin/60099; it has been noted by GNATS.

From: "Robert Elz" <kre%netbsd.org@localhost>
To: gnats-bugs%gnats.NetBSD.org@localhost
Cc: 
Subject: PR/60099 CVS commit: src/tests/bin/sh
Date: Mon, 23 Mar 2026 17:16:04 +0000

 Module Name:	src
 Committed By:	kre
 Date:		Mon Mar 23 17:16:03 UTC 2026
 
 Modified Files:
 	src/tests/bin/sh: t_expand.sh t_fsplit.sh
 
 Log Message:
 Fix sh tests failing after the PR 60099 fix to /bin/sh
 
 After the fix for PR 60099 was applied to /bin/sh, 2 of the
 sh ATF tests no longer give the same output as they used to:
 
 In t_expand:dollar_at_empty_and_conditional
 
 	set -- "a+a" "" "b " " c"; IFS=+; delim_argv $*"$@"
 
 That creates 4 positional params, (as shown), so $*"$@"
 should be the same as
 
 	$1    $2  $3     $4"$1"  "$2"  "$3"  "$4"
 	'a+a' ''  'b ' ' c'"a+a" ""    "b "  " c"
 
 where the single quotes are just so the values can be detected,
 double quotes indicate quoted values.
 
 The unquoted $* values are then field split, using IFS=+ (which only
 affects the $1 value, the only unquoted value with a + in it) and
 the $2 value, as that's unquoted nothing, and gets deleted.
 
 	a  a     'b '  'c '"a+a"  "" "b " " c"
 
 with $1 turning into two fields, and $2 (being nothing) vanishing.
 There is no space in IFS, so the spaces are retained.
 
 This is what we now get, and that's correct.  It is also what would be
 obtained (now, and previously) if it was actually written in the
 $1 $2 $3 $4 form, instead of as $* which should be the same thing
 (assuming we know how many positional params to write out).
 
 The old code used to expand $* as if it were "$*" but just omit the
 quotes, that led to (as IFS=+)
 
 	'a+a++b + c'"a+a" "" "b " " c"
 
 where the '' are just to show the current state, after which that
 word was field split, using IFS=+ for which the correct result, given
 that input, is
 
 	a a '' 'b ' ' c'"a+a" "" "b " " c"
 
 which was the old result.  Here, what was $2 became an explicitly empty
 field that field splitting is required to retain.   That isn't the same
 as what happened if the $* was hand expanded, and so was always incorrect.
 
 The t_fsplit:split_arith test that failed was
 
 	IFS=1; set -- $(( 1111 )); echo "$#:" $*'
 
 The set command set 4 positional parameters, all to '' (as the
 value is "1111" IFS=1 so each '1' in the value ends a field,
 there are 4 of them, and nothing else, so we get 4 empty fields.)
 
 That's correct, and always was, and the $# produced 4 as expected,
 and still does.
 
 The $* however should be the same as $1 $2 $3 $4 (as $# == 4) where each
 of those expands to an unquoted empty string - ie: nothing, so the $*
 apparent 2nd (and perhaps later) arg(s) to "echo" should simply vanish.
 That's what we get now.
 
 The old code however expanded the $* ('' '' '' '') as if it were
 "$*" with IFS=1 that is, producing
 	''1''1''1''
 or just 111.  That's then field split (using IFS=1), producing 3 empty
 fields, all of which were retained.   That caused echo to write 3 spaces
 after the ':', one before each of the 3 additional (empty) args it was
 given.   Had the echo command been "echo "$#:" $1 $2 $3 $4 the positional
 params, all being unquoted and empty, would simply have vanished (that's
 required) so echo would only have the 1st arg, and would write no trailing
 spaces.   That's what the new code produces in the $* case.
 
 
 To generate a diff of this commit:
 cvs rdiff -u -r1.26 -r1.27 src/tests/bin/sh/t_expand.sh
 cvs rdiff -u -r1.10 -r1.11 src/tests/bin/sh/t_fsplit.sh
 
 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.
 



Home | Main Index | Thread Index | Old Index