zsh-users
 help / color / mirror / code / Atom feed
* Why a '-quoted string isn't respected by // subst, while \-quoted is?
@ 2023-01-25 11:04 Sebastian Gniazdowski
  2023-01-25 12:36 ` Roman Perepelitsa
  0 siblings, 1 reply; 7+ messages in thread
From: Sebastian Gniazdowski @ 2023-01-25 11:04 UTC (permalink / raw)
  To: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 519 bytes --]

Hi,
I'm storing a pattern in a var:

E="0='\${\${\\(M\\)\${0::=\${\\(%\\):-%x}}:\\#/\\*}:-\$PWD/\$0}'"

to then match it against:

Q='0=${${(M)${0::=${(%):-%x}}:#/*}:-$PWD/$0}'

with // substitution:

printf %s\\n $E $Q ${Q//$~E/q}

The result is no match. However, if I instead quote the string with \:

E='0=${${\(M\)${0::=${\(%\):-%x}}:\#/*}:-$PWD/$0}'

(only ),(,#,* are quoted), then it matches. Why? It would be more
comfortable to simply quote with ' the whole string...

-- 
Best regards,
Sebastian Gniazdowski

[-- Attachment #2: Type: text/html, Size: 2119 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Why a '-quoted string isn't respected by // subst, while \-quoted is?
  2023-01-25 11:04 Why a '-quoted string isn't respected by // subst, while \-quoted is? Sebastian Gniazdowski
@ 2023-01-25 12:36 ` Roman Perepelitsa
  2023-01-25 12:59   ` Sebastian Gniazdowski
  0 siblings, 1 reply; 7+ messages in thread
From: Roman Perepelitsa @ 2023-01-25 12:36 UTC (permalink / raw)
  To: Sebastian Gniazdowski; +Cc: Zsh Users

On Wed, Jan 25, 2023 at 12:05 PM Sebastian Gniazdowski
<sgniazdowski@gmail.com> wrote:
>
> Hi,
> I'm storing a pattern in a var:
>
> E="0='\${\${\\(M\\)\${0::=\${\\(%\\):-%x}}:\\#/\\*}:-\$PWD/\$0}'"
>
> to then match it against:
>
> Q='0=${${(M)${0::=${(%):-%x}}:#/*}:-$PWD/$0}'
>
> with // substitution:
>
> printf %s\\n $E $Q ${Q//$~E/q}
>
> The result is no match. However, if I instead quote the string with \:
>
> E='0=${${\(M\)${0::=${\(%\):-%x}}:\#/*}:-$PWD/$0}'

You can print them to see the difference:

    % E="0='\${\${\\(M\\)\${0::=\${\\(%\\):-%x}}:\\#/\\*}:-\$PWD/\$0}'"
    % print -r -- $E
    0='${${\(M\)${0::=${\(%\):-%x}}:\#/\*}:-$PWD/$0}'

    % E='0=${${\(M\)${0::=${\(%\):-%x}}:\#/*}:-$PWD/$0}'
    % print -r -- $E
    0=${${\(M\)${0::=${\(%\):-%x}}:\#/*}:-$PWD/$0}

As you can see, the first `E` has three extra characters: two quotes
and a backslash.

Roman.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Why a '-quoted string isn't respected by // subst, while \-quoted is?
  2023-01-25 12:36 ` Roman Perepelitsa
@ 2023-01-25 12:59   ` Sebastian Gniazdowski
  2023-01-25 13:09     ` Sebastian Gniazdowski
  2023-01-25 13:10     ` Roman Perepelitsa
  0 siblings, 2 replies; 7+ messages in thread
From: Sebastian Gniazdowski @ 2023-01-25 12:59 UTC (permalink / raw)
  To: Roman Perepelitsa; +Cc: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 1501 bytes --]

Ok, I'll take a closer look, however I'm now struggling with similar
problem:

QE='0=${${(M)${0::=${(%):-%x}}:#/*}:-$PWD/$0}'
print ${QE//'0=${${(M)${0::=${(%):-%x}}:#/*}:-$PWD/$0}'/°match°}

the strings in QE and in …//'…'/… are identical. Why no match? A simpler
example works as expected:

QE=qeqe
print ${(S)QE//'qeqe'/°match°}

Output:

°match°

On Wed, 25 Jan 2023 at 12:36, Roman Perepelitsa <roman.perepelitsa@gmail.com>
wrote:

> On Wed, Jan 25, 2023 at 12:05 PM Sebastian Gniazdowski
> <sgniazdowski@gmail.com> wrote:
> >
> > Hi,
> > I'm storing a pattern in a var:
> >
> > E="0='\${\${\\(M\\)\${0::=\${\\(%\\):-%x}}:\\#/\\*}:-\$PWD/\$0}'"
> >
> > to then match it against:
> >
> > Q='0=${${(M)${0::=${(%):-%x}}:#/*}:-$PWD/$0}'
> >
> > with // substitution:
> >
> > printf %s\\n $E $Q ${Q//$~E/q}
> >
> > The result is no match. However, if I instead quote the string with \:
> >
> > E='0=${${\(M\)${0::=${\(%\):-%x}}:\#/*}:-$PWD/$0}'
>
> You can print them to see the difference:
>
>     % E="0='\${\${\\(M\\)\${0::=\${\\(%\\):-%x}}:\\#/\\*}:-\$PWD/\$0}'"
>     % print -r -- $E
>     0='${${\(M\)${0::=${\(%\):-%x}}:\#/\*}:-$PWD/$0}'
>
>     % E='0=${${\(M\)${0::=${\(%\):-%x}}:\#/*}:-$PWD/$0}'
>     % print -r -- $E
>     0=${${\(M\)${0::=${\(%\):-%x}}:\#/*}:-$PWD/$0}
>
> As you can see, the first `E` has three extra characters: two quotes
> and a backslash.
>
> Roman.
>


-- 
Best regards,
Sebastian Gniazdowski

[-- Attachment #2: Type: text/html, Size: 3196 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Why a '-quoted string isn't respected by // subst, while \-quoted is?
  2023-01-25 12:59   ` Sebastian Gniazdowski
@ 2023-01-25 13:09     ` Sebastian Gniazdowski
  2023-01-25 13:10     ` Roman Perepelitsa
  1 sibling, 0 replies; 7+ messages in thread
From: Sebastian Gniazdowski @ 2023-01-25 13:09 UTC (permalink / raw)
  To: Roman Perepelitsa; +Cc: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 2018 bytes --]

It seems that it's / within the '-quoted string that causes the problem:

print ${QE//'0=${${(M)${0::=${(%):-%x}}:#\/*}:-$PWD\/$0}'/°match°}

outputs °match°, while:

print ${QE//'0=${${(M)${0::=${(%):-%x}}:#/*}:-$PWD/$0}'/°match°}

doesn't. Isn't it a bug of ignoring '-quoting of /?


On Wed, 25 Jan 2023 at 12:59, Sebastian Gniazdowski <sgniazdowski@gmail.com>
wrote:

> Ok, I'll take a closer look, however I'm now struggling with similar
> problem:
>
> QE='0=${${(M)${0::=${(%):-%x}}:#/*}:-$PWD/$0}'
> print ${QE//'0=${${(M)${0::=${(%):-%x}}:#/*}:-$PWD/$0}'/°match°}
>
> the strings in QE and in …//'…'/… are identical. Why no match? A simpler
> example works as expected:
>
> QE=qeqe
> print ${(S)QE//'qeqe'/°match°}
>
> Output:
>
> °match°
>
> On Wed, 25 Jan 2023 at 12:36, Roman Perepelitsa <
> roman.perepelitsa@gmail.com> wrote:
>
>> On Wed, Jan 25, 2023 at 12:05 PM Sebastian Gniazdowski
>> <sgniazdowski@gmail.com> wrote:
>> >
>> > Hi,
>> > I'm storing a pattern in a var:
>> >
>> > E="0='\${\${\\(M\\)\${0::=\${\\(%\\):-%x}}:\\#/\\*}:-\$PWD/\$0}'"
>> >
>> > to then match it against:
>> >
>> > Q='0=${${(M)${0::=${(%):-%x}}:#/*}:-$PWD/$0}'
>> >
>> > with // substitution:
>> >
>> > printf %s\\n $E $Q ${Q//$~E/q}
>> >
>> > The result is no match. However, if I instead quote the string with \:
>> >
>> > E='0=${${\(M\)${0::=${\(%\):-%x}}:\#/*}:-$PWD/$0}'
>>
>> You can print them to see the difference:
>>
>>     % E="0='\${\${\\(M\\)\${0::=\${\\(%\\):-%x}}:\\#/\\*}:-\$PWD/\$0}'"
>>     % print -r -- $E
>>     0='${${\(M\)${0::=${\(%\):-%x}}:\#/\*}:-$PWD/$0}'
>>
>>     % E='0=${${\(M\)${0::=${\(%\):-%x}}:\#/*}:-$PWD/$0}'
>>     % print -r -- $E
>>     0=${${\(M\)${0::=${\(%\):-%x}}:\#/*}:-$PWD/$0}
>>
>> As you can see, the first `E` has three extra characters: two quotes
>> and a backslash.
>>
>> Roman.
>>
>
>
> --
> Best regards,
> Sebastian Gniazdowski
>
>

-- 
Best regards,
Sebastian Gniazdowski

[-- Attachment #2: Type: text/html, Size: 4857 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Why a '-quoted string isn't respected by // subst, while \-quoted is?
  2023-01-25 12:59   ` Sebastian Gniazdowski
  2023-01-25 13:09     ` Sebastian Gniazdowski
@ 2023-01-25 13:10     ` Roman Perepelitsa
  2023-01-27 18:43       ` Daniel Shahaf
  1 sibling, 1 reply; 7+ messages in thread
From: Roman Perepelitsa @ 2023-01-25 13:10 UTC (permalink / raw)
  To: Sebastian Gniazdowski; +Cc: Zsh Users

On Wed, Jan 25, 2023 at 2:00 PM Sebastian Gniazdowski
<sgniazdowski@gmail.com> wrote:
>
> Ok, I'll take a closer look, however I'm now struggling with similar problem:
>
> QE='0=${${(M)${0::=${(%):-%x}}:#/*}:-$PWD/$0}'
> print ${QE//'0=${${(M)${0::=${(%):-%x}}:#/*}:-$PWD/$0}'/°match°}
>
> the strings in QE and in …//'…'/… are identical. Why no match?

This looks like a bug in zsh. Here's a simpler test case:

    % x='/'
    % print -r -- ${x/'/'}
    /

I expect the output to be empty but it's in fact "/".

This one also looks wrong:

    % x=\'
    % print -r -- ${x/'/'}

Here the output is empty while I expect a single quote.

Roman.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Why a '-quoted string isn't respected by // subst, while \-quoted is?
  2023-01-25 13:10     ` Roman Perepelitsa
@ 2023-01-27 18:43       ` Daniel Shahaf
  2023-01-27 19:38         ` Bart Schaefer
  0 siblings, 1 reply; 7+ messages in thread
From: Daniel Shahaf @ 2023-01-27 18:43 UTC (permalink / raw)
  To: Roman Perepelitsa; +Cc: Sebastian Gniazdowski, Zsh Users

Roman Perepelitsa wrote on Wed, Jan 25, 2023 at 14:10:26 +0100:
> On Wed, Jan 25, 2023 at 2:00 PM Sebastian Gniazdowski
> <sgniazdowski@gmail.com> wrote:
> >
> > Ok, I'll take a closer look, however I'm now struggling with similar problem:
> >
> > QE='0=${${(M)${0::=${(%):-%x}}:#/*}:-$PWD/$0}'
> > print ${QE//'0=${${(M)${0::=${(%):-%x}}:#/*}:-$PWD/$0}'/°match°}
> >
> > the strings in QE and in …//'…'/… are identical. Why no match?
> 
> This looks like a bug in zsh. Here's a simpler test case:
> 
>     % x='/'
>     % print -r -- ${x/'/'}
>     /
> 
> I expect the output to be empty but it's in fact "/".
> 
> This one also looks wrong:
> 
>     % x=\'
>     % print -r -- ${x/'/'}
> 
> Here the output is empty while I expect a single quote.

XFail regression tests added in 096e72ce78ac.

Cheers,

Daniel


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Why a '-quoted string isn't respected by // subst, while \-quoted is?
  2023-01-27 18:43       ` Daniel Shahaf
@ 2023-01-27 19:38         ` Bart Schaefer
  0 siblings, 0 replies; 7+ messages in thread
From: Bart Schaefer @ 2023-01-27 19:38 UTC (permalink / raw)
  To: Daniel Shahaf; +Cc: Roman Perepelitsa, Sebastian Gniazdowski, Zsh Users

On Fri, Jan 27, 2023 at 10:44 AM Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
>
> XFail regression tests added in 096e72ce78ac.

See also workers/51202


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-01-27 19:39 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-25 11:04 Why a '-quoted string isn't respected by // subst, while \-quoted is? Sebastian Gniazdowski
2023-01-25 12:36 ` Roman Perepelitsa
2023-01-25 12:59   ` Sebastian Gniazdowski
2023-01-25 13:09     ` Sebastian Gniazdowski
2023-01-25 13:10     ` Roman Perepelitsa
2023-01-27 18:43       ` Daniel Shahaf
2023-01-27 19:38         ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).