bug-bash
[Top][All Lists]
Advanced

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

Re: [PATCH] WIP: quote_string_for_globbing: unquoted backslash


From: Chet Ramey
Subject: Re: [PATCH] WIP: quote_string_for_globbing: unquoted backslash
Date: Sat, 7 Oct 2023 13:42:43 -0400
User-agent: Mozilla Thunderbird

On 9/26/23 2:50 AM, Grisha Levit wrote:
I'm not confident in what the right behavior is here, and maybe there is
no obvious one, but I _think_ this is not desirable:

If an unquoted backslash is followed by a quoted globbing character,
quote_string_for_globbing will store the unquoted backslash and then also
another one to quote the character -- resulting in the originally quoted
character becoming unquoted:

$ bash -cx '[[ \\FOO == $1"*" ]]' _ '\'; echo $?
+ [[ \FOO == \\* ]]
0

It's hard to say. There's only one way to quote a character for globbing:
using a backslash. The expansion of $1 isn't quoted, so there's no reason
to quote that backslash, but the `*' is, so you have to quote it somehow,
and the only way to do that is with a backslash.

This behavior is compatible with ksh93, at least, so you can conclude
that both implementations see it the same way.


This patch would need some more work but I wanted to see what the
correct behaviour should be first.  Also, I don't really understand how
this function can work correctly without the QGLOB_CTLNUL flag -- it
seems there wouldn't be a way to distinguish literal CTLESC's from ones
serving the quoting function.

Do you mean QGLOB_CTLESC or QGLOB_CVTNULL (I assume the former)? It
distinguishes the cases of calling quote_string_for_globbing while
the string is still quoted and when quote removal has been performed
or isn't appropriate (or before CTLESC quoting has been applied,
potentially).

For instance, if you look at the calls to shell_glob_filename, they include
word completion, where you don't want to convert any CTLESCs because the
parser hasn't processed them. So it's the responsibility of the caller to
determine whether the CTLESCs escaping CTLESC or CTLNUL should be treated
as quoting characters, and pass the right flag.

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]