Skip to contentSkip to conversation

Field splitting regression on master branch

PATCH New Martijn Dekker 3 participants 3 messages Jun 21, 2024 – Jun 22, 2024

lore
Share & tools
lore
#0 lore raw

As of commit c0674f487c7aec2a3bdf6795cea7e60c9530c360, field splitting is broken. Minimal-ish reproducer:

$ dash -c 'IFS=:; v=" :: :: "; set $v; echo $#'
5

Expected output: 2

FYI, this is a nice cross-platform script for testing for field splitting regressions (on dash as well):

http://web.archive.org/web/20051225040851/http://www.research.att.com/~gsf/public/ifs.sh

Dash passes this prior to the referenced commit, and fails it after, in informative ways.

Signature · 5 lines
||	modernish -- harness the shell
||	https://github.com/modernish/modernish
||
||	KornShell lives!
||	https://github.com/ksh93/ksh
#1 lore raw
Quoted 6 lines · Martijn Dekker

As of commit c0674f487c7aec2a3bdf6795cea7e60c9530c360, field splitting is broken. Minimal-ish reproducer:

$ dash -c 'IFS=:; v=" :: :: "; set $v; echo $#'
5

Expected output: 2

This results in 5 in bash, ksh, older dash, yash, everything I can think to test. Whitespace IFS characters is meant to be handled differently from non-whitespace IFS characters, I think 5 is the correct result.

But with IFS=": " instead of IFS=:, the output was previously 4, is supposed to be 4, and has changed to 2; I agree that it looks like dash has introduced a bug here.

Cheers,
Harald van Dijk

#2 lore raw

PATCH 1/1 expand: Fix leading white space regression in ifsbreakup

In reply to Martijn Dekker
Quoted 8 lines · Martijn Dekker

As of commit c0674f487c7aec2a3bdf6795cea7e60c9530c360, field splitting is broken. Minimal-ish reproducer:

$ dash -c 'IFS=:; v=" :: :: "; set $v; echo $#'
5

Expected output: 2

Quoted 7 lines

FYI, this is a nice cross-platform script for testing for field splitting regressions (on dash as well):

http://web.archive.org/web/20051225040851/http://www.research.att.com/~gsf/public/ifs.sh

Dash passes this prior to the referenced commit, and fails it after, in informative ways.

Thanks for the report. This patch should fix the problem:

---8<---
When leading white spaces are detected in ifsbreakup ifsspc needs to be cleared.

Fixes c0674f487c7a ("expand: Support multi-byte characters during field splitting")
---
 src/expand.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
src/expand.c +2 -1
index 6912e39..5285b79 100644
@@ -1282,7 +1282,7 @@ static char *ifsbreakup_slow(struct ifs_state *ifst, struct arglist *arglist,
 		/* Ignore IFS whitespace at start */
 		if (q == ifst->start && ifsspc) {
 			ifst->start = p;
-			return p;
+			goto out_zero_ifsspc;
 		}
 		if (ifst->maxargs > 0 && !--ifst->maxargs) {
 			ifst->r = q;
@@ -1297,6 +1297,7 @@ static char *ifsbreakup_slow(struct ifs_state *ifst, struct arglist *arglist,
 		return p;
 	}
 
+out_zero_ifsspc:
 	ifst->ifsspc = 0;
 	return p;
 }
Signature · 5 lines
2.39.2
-- 
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt