Skip to contentSkip to conversation

Regression in quoted remove-longest-prefix expansion

DISCUSSION Johannes Altmanninger 2 participants 3 messages Feb 22, 2025 – Mar 17, 2025

lore
Share & tools
lore
#0 lore raw

I noticed another regression in c5bf970 (expand: Add multi-byte support to pmatch, 2024-06-02).

This command now prints "abc-def" but used to print "ef".

	x=abc-def
	y="${x##*d}"
	echo "$y"
#1 lore raw

expand: Fix scanright zero handling when fnmatch is disabled

Quoted 8 lines · Johannes Altmanninger

I noticed another regression in c5bf970 (expand: Add multi-byte support to pmatch, 2024-06-02).

This command now prints "abc-def" but used to print "ef".

       x=abc-def
       y="${x##*d}"
       echo "$y"

Fix this by setting s to the correct value in scanright based on FNMATCH_IS_ENABLED.

Fixes c5bf9702ea11 ("expand: Add multi-byte support to pmatch")
src/expand.c +1 -1
index 7a30648..0066e1a 100644
@@ -650,7 +650,7 @@ static char *scanright(char *startp, char *endp, char *rmesc, char *rmescend,
 
 		if (zero) {
 			*s = '\0';
-			s = rmesc;
+			s = FNMATCH_IS_ENABLED ? rmesc : startp;
 		}
 		match = pmatch(str, s);
 		*(FNMATCH_IS_ENABLED ? loc2 : loc) = c;

Thanks,

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
#2 lore raw

Re: expand: Fix scanright zero handling when fnmatch is disabled

Quoted 21 lines · Herbert Xu
Quoted 8 lines · Johannes Altmanninger

I noticed another regression in c5bf970 (expand: Add multi-byte support to pmatch, 2024-06-02).

This command now prints "abc-def" but used to print "ef".

       x=abc-def
       y="${x##*d}"
       echo "$y"

Fix this by setting s to the correct value in scanright based on FNMATCH_IS_ENABLED.

Fixes c5bf9702ea11 ("expand: Add multi-byte support to pmatch")
src/expand.c +0 -0
index 7a30648..0066e1a 100644

src/expand.c static char *scanright(char *startp, char *endp, char *rmesc, char *rmescend, · line 653

Quoted 5 lines
src/expand.c +1 -1
@@ -650,7 +650,7 @@ static char *scanright(char *startp, char *endp, char *rmesc, char *rmescend,
 
 		if (zero) {
 			*s = '\0';
-			s = rmesc;
+			s = FNMATCH_IS_ENABLED ? rmesc : startp;

Seems to work, thanks. I can go back to running master now (with
https://lore.kernel.org/dash/[email protected]/
applied too)