From: Herbert Xu <herbert@gondor.apana.org.au>
To: Martijn Dekker <martijn@inlv.org>
Cc: dash@vger.kernel.org
Subject: [PATCH] expand: Fix leading white space regression in ifsbreakup
Date: Sat, 22 Jun 2024 20:19:22 +0800 [thread overview]
Message-ID: <ZnbBSnDM7aGUAb5L@gondor.apana.org.au> (raw)
In-Reply-To: <b19b7107-097e-4865-a0d9-26cdf316c1c4@inlv.org>
Martijn Dekker <martijn@inlv.org> wrote:
> 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.
Thanks for the report. This patch should fix the problem:
---8<---
When leading white spaces are detected in ifsbreakup ifsspc needs
to be cleared.
Reported-by: Martijn Dekker <martijn@inlv.org>
Fixes: c0674f487c7a ("expand: Support multi-byte characters during field splitting")
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
---
src/expand.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/expand.c b/src/expand.c
index 6912e39..5285b79 100644
--- a/src/expand.c
+++ b/src/expand.c
@@ -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;
}
--
2.39.2
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
prev parent reply other threads:[~2024-06-22 12:26 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-21 1:33 Field splitting regression on master branch Martijn Dekker
2024-06-21 3:07 ` Harald van Dijk
2024-06-22 12:19 ` Herbert Xu [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZnbBSnDM7aGUAb5L@gondor.apana.org.au \
--to=herbert@gondor.apana.org.au \
--cc=dash@vger.kernel.org \
--cc=martijn@inlv.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox