Re: [PATCH] expand: Fix naked backslah leakage

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

 



On 27/04/2024 13:22, Herbert Xu wrote:
On Sat, Apr 27, 2024 at 01:12:19PM +0100, Harald van Dijk wrote:

The correct result here, I believe, is <\*bc>. The backslash means the next
character is taken as literal, even if that character is already also taken
as literal because of the quoting. There is nothing to cause the backslash
to be taken literally. The result should be that only a leading * is removed
from $a.

While I do see the logic in your reasoning, no other shell implements
this behaviour:

I'm aware this isn't what most shells do, but it's not quite the case that no other shell implements this.

*sh -c 'a="*bc"; b="\\"; c="*"; echo "<${a##$b"$c"}>"'

always produces <*bc> across all shells on my system.

This produces <bc> with my shell, at least.

If we are comparing what other shells do, it is probably worth pointing out that shells disagree on your original example.

  a="\\*bc"; b="\\"; c="*"; echo "<${a##$b"$c"}>"

Many shells share the bug where this prints <>, but of shells that do not have this bug, while many print <bc> like what your patch makes dash do, the most commonly used one, bash (as of version 4), does not: it prints <\*bc>. I am not sure what exactly $b"$c" is trying to strip here.

Cheers,
Harald van Dijk




[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux