zsh-workers
 help / color / mirror / code / Atom feed
* [BUG] Weird _expand & _complete behavior for $parameters in "double quotes"
@ 2021-05-11 10:24 Marlon Richert
  2021-05-11 11:05 ` Bart Schaefer
  0 siblings, 1 reply; 8+ messages in thread
From: Marlon Richert @ 2021-05-11 10:24 UTC (permalink / raw)
  To: Zsh hackers list

Tested with 9e38ab81785c4ac755a7e78d2fe7a7db92bdf375:

  comptesteval "typeset -a bar=({$'\\0'..$'\\C-?'})"
  comptesteval 'typeset -A bat=( "$bar[@]" )'
  comptesteval 'typeset bay="$bar"'
  comptesteval 'unsetopt listambiguous'
  comptest $': "$ba"\C-B\t\t'
0: complete parameter in double quotes
>line: {: "$ba}{"}
>DESCRIPTION:{parameter}
>NO:{bar}
>NO:{bat}
>NO:{bay}
>line: {: "$bar}{"}

% make TESTNUM=Y01 check
[...]
-line: {: "$ba}{"}
+line: {: "$ba}{""}
 DESCRIPTION:{parameter}
 NO:{bar}
 NO:{bat}
 NO:{bay}
-line: {: "$bar}{"}
+line: {: \"\"\"}{}
+DESCRIPTION:{expansions}
+NO:{\"\"\"}
+DESCRIPTION:{all expansions}
+NO:{\"\"\"}
+DESCRIPTION:{original}
+NO:{"$ba""}
Test ./Y01completion.ztst failed: output differs from expected as
shown above for:
  comptesteval 'unsetopt listambiguous'
  comptest $': "$ba"\C-B\t\t'
Was testing:  complete parameter in double quotes


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

* Re: [BUG] Weird _expand & _complete behavior for $parameters in "double quotes"
  2021-05-11 10:24 [BUG] Weird _expand & _complete behavior for $parameters in "double quotes" Marlon Richert
@ 2021-05-11 11:05 ` Bart Schaefer
  2021-05-11 17:32   ` Marlon Richert
  0 siblings, 1 reply; 8+ messages in thread
From: Bart Schaefer @ 2021-05-11 11:05 UTC (permalink / raw)
  To: Marlon Richert; +Cc: Zsh hackers list

I can't reproduce this on either Ubutu or MacOS, nor either with or
without my completeinword patch from the other day.


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

* Re: [BUG] Weird _expand & _complete behavior for $parameters in "double quotes"
  2021-05-11 11:05 ` Bart Schaefer
@ 2021-05-11 17:32   ` Marlon Richert
  2021-05-11 19:40     ` Bart Schaefer
  2021-05-23 21:02     ` Lawrence Velázquez
  0 siblings, 2 replies; 8+ messages in thread
From: Marlon Richert @ 2021-05-11 17:32 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh hackers list

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

On Tue, May 11, 2021 at 2:05 PM Bart Schaefer <schaefer@brasslantern.com> wrote:
>
> I can't reproduce this on either Ubutu or MacOS, nor either with or
> without my completeinword patch from the other day.

I tried it again, but this time as follows:

make realclean
Util/preconfig
configure
make all TESTNUM=Y01 check

I still get the exact same test failure. macOS, commit
9e38ab81785c4ac755a7e78d2fe7a7db92bdf375.

Here's the test as a patch, in case it helps you reproduce it.

[-- Attachment #2: 0001-_expand-_complete-parameters-in-double-quotes.txt --]
[-- Type: text/plain, Size: 1179 bytes --]

From f5d77fe457da42de2bb23ba95476cc14466d19c0 Mon Sep 17 00:00:00 2001
From: Marlon Richert <marlon.richert@gmail.com>
Date: Tue, 11 May 2021 20:27:50 +0300
Subject: [PATCH] _expand & _complete $parameters in "double quotes"

---
 Test/Y01completion.ztst | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/Test/Y01completion.ztst b/Test/Y01completion.ztst
index 2c6d25d9a..8034f0c67 100644
--- a/Test/Y01completion.ztst
+++ b/Test/Y01completion.ztst
@@ -282,6 +282,19 @@ F:regression test workers/31611
 >NO:{bar}
 >NO:{baz}
 
+  comptesteval "typeset -a bar=({$'\\0'..$'\\C-?'})"
+  comptesteval 'typeset -A bat=( "$bar[@]" )'
+  comptesteval 'typeset bay="$bar"'
+  comptesteval 'unsetopt listambiguous'
+  comptest $': "$ba"\C-B\t\t'
+0: complete parameter in double quotes
+>line: {: "$ba}{"}
+>DESCRIPTION:{parameter}
+>NO:{bar}
+>NO:{bat}
+>NO:{bay}
+>line: {: "$bar}{"}
+
   comptesteval '_tst() { local disp=( {a..z} ); compadd -ld disp $disp[@]; comppostfuncs=( _pst ) }'
   comptesteval '_pst() { local disp=( "<INSERT>$compstate[insert]</INSERT>" ); compadd -Qld disp $disp }'
   comptesteval "zstyle ':completion:*' menu select=long-list"
-- 
2.31.1


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

* Re: [BUG] Weird _expand & _complete behavior for $parameters in "double quotes"
  2021-05-11 17:32   ` Marlon Richert
@ 2021-05-11 19:40     ` Bart Schaefer
  2021-05-12  6:43       ` Marlon Richert
  2021-05-23 21:02     ` Lawrence Velázquez
  1 sibling, 1 reply; 8+ messages in thread
From: Bart Schaefer @ 2021-05-11 19:40 UTC (permalink / raw)
  To: Marlon Richert; +Cc: Zsh hackers list

On Tue, May 11, 2021 at 10:32 AM Marlon Richert
<marlon.richert@gmail.com> wrote:
>
> On Tue, May 11, 2021 at 2:05 PM Bart Schaefer <schaefer@brasslantern.com> wrote:
> >
> > I can't reproduce this on either Ubutu or MacOS, nor either with or
> > without my completeinword patch from the other day.
>
> Here's the test as a patch, in case it helps you reproduce it.

Ah, I didn't get before that you'd added an entire new test case.

There are two things going on here:

One, complete-in-word handling of quotes has several problems, which
I've unsuccessfully wrestled with once or twice before.  Completion
wants to remove the quotes, complete what is inside them, and then put
back the most appropriate quotes for the end result, which aren't
always the same as the original quotes ... and it can get pretty
confused along the way.  So the first TAB replaces "$ba" with "$ba""
because it recognizes the ambiguous prefix but forgets (so to speak)
that there's already a trailing quote.

Two, on the next tab when _expand sees the extra quote, it concludes
that $ba is the entire variable to be expanded, and replaces it with
the empty string.  The quotes then all themselves get quoted (see "put
back the most appropriate"+"confused"), leaving \"\"\".

This may be in some way related to the do_ambiguous() discussion from
workers/39123 all the way back in 2016, which never got any further
(and the patch from workers/39968 never did get committed, but it
doesn't help with this quoting situation).


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

* Re: [BUG] Weird _expand & _complete behavior for $parameters in "double quotes"
  2021-05-11 19:40     ` Bart Schaefer
@ 2021-05-12  6:43       ` Marlon Richert
  0 siblings, 0 replies; 8+ messages in thread
From: Marlon Richert @ 2021-05-12  6:43 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh hackers list

On Tue, May 11, 2021 at 10:40 PM Bart Schaefer
<schaefer@brasslantern.com> wrote:
>
> On Tue, May 11, 2021 at 10:32 AM Marlon Richert
> <marlon.richert@gmail.com> wrote:
> >
> > On Tue, May 11, 2021 at 2:05 PM Bart Schaefer <schaefer@brasslantern.com> wrote:
> > >
> > > I can't reproduce this on either Ubutu or MacOS, nor either with or
> > > without my completeinword patch from the other day.
> >
> > Here's the test as a patch, in case it helps you reproduce it.
>
> Ah, I didn't get before that you'd added an entire new test case.

Sorry about the confusion. Yes, I added a new test case, because I saw
this happen on the command line, but I wanted to make sure that A) it
wasn't just my environment and B) I presented the bug in a way that
you could easily reproduce it. Next time, I guess I'll just send it as
a patch in the first place. :)

> There are two things going on here:
>
> One, complete-in-word handling of quotes has several problems, which
> I've unsuccessfully wrestled with once or twice before.

Note that my test case does not set COMPLETE_IN_WORD and setting it
doesn't appear to make any difference for this case.


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

* Re: [BUG] Weird _expand & _complete behavior for $parameters in "double quotes"
  2021-05-11 17:32   ` Marlon Richert
  2021-05-11 19:40     ` Bart Schaefer
@ 2021-05-23 21:02     ` Lawrence Velázquez
  2021-05-24 20:13       ` Bart Schaefer
  1 sibling, 1 reply; 8+ messages in thread
From: Lawrence Velázquez @ 2021-05-23 21:02 UTC (permalink / raw)
  To: zsh-workers; +Cc: Marlon Richert

On Tue, May 11, 2021, at 1:32 PM, Marlon Richert wrote:
> I tried it again, but this time as follows:
> 
> make realclean
> Util/preconfig
> configure
> make all TESTNUM=Y01 check
> 
> I still get the exact same test failure. macOS, commit
> 9e38ab81785c4ac755a7e78d2fe7a7db92bdf375.
> 
> Here's the test as a patch, in case it helps you reproduce it.
> 
> Attachments:
> * 0001-_expand-_complete-parameters-in-double-quotes.txt

Should this test case be committed?

-- 
vq


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

* Re: [BUG] Weird _expand & _complete behavior for $parameters in "double quotes"
  2021-05-23 21:02     ` Lawrence Velázquez
@ 2021-05-24 20:13       ` Bart Schaefer
  2021-05-24 20:19         ` Daniel Shahaf
  0 siblings, 1 reply; 8+ messages in thread
From: Bart Schaefer @ 2021-05-24 20:13 UTC (permalink / raw)
  To: Lawrence Velázquez; +Cc: Zsh hackers list, Marlon Richert

On Sun, May 23, 2021 at 2:04 PM Lawrence Velázquez <larryv@zsh.org> wrote:
>
> On Tue, May 11, 2021, at 1:32 PM, Marlon Richert wrote:
> > * 0001-_expand-_complete-parameters-in-double-quotes.txt
>
> Should this test case be committed?

I would say "no".  At best it would be an "xfail" test, but we don't
yet know if the eventual non-error output will match what Marlon
expected when he made up the test.


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

* Re: [BUG] Weird _expand & _complete behavior for $parameters in "double quotes"
  2021-05-24 20:13       ` Bart Schaefer
@ 2021-05-24 20:19         ` Daniel Shahaf
  0 siblings, 0 replies; 8+ messages in thread
From: Daniel Shahaf @ 2021-05-24 20:19 UTC (permalink / raw)
  To: Zsh hackers list; +Cc: Lawrence Velázquez, Marlon Richert

Bart Schaefer wrote on Mon, May 24, 2021 at 13:13:04 -0700:
> On Sun, May 23, 2021 at 2:04 PM Lawrence Velázquez <larryv@zsh.org> wrote:
> >
> > On Tue, May 11, 2021, at 1:32 PM, Marlon Richert wrote:
> > > * 0001-_expand-_complete-parameters-in-double-quotes.txt
> >
> > Should this test case be committed?
> 
> I would say "no".  At best it would be an "xfail" test, but we don't
> yet know if the eventual non-error output will match what Marlon
> expected when he made up the test.

We could still do the following, though?  Based on Marlon's patch, but
with expectations adjusted.

diff --git a/Test/Y01completion.ztst b/Test/Y01completion.ztst
index 882a0adc4..f507996f1 100644
--- a/Test/Y01completion.ztst
+++ b/Test/Y01completion.ztst
@@ -322,6 +322,14 @@ F:regression test workers/31611
 >NO:{y}
 >NO:{z}
 
+  comptesteval "typeset -a bar=({$'\\0'..$'\\C-?'})"
+  comptesteval 'typeset -A bat=( "$bar[@]" )'
+  comptesteval 'typeset bay="$bar"'
+  comptesteval 'unsetopt listambiguous'
+  comptest $': "$ba"\C-B\t\t' | fgrep line: | fgrep '\"\"\"'
+-Df: complete parameter in double quotes
+# When this test starts to pass, add proper expectations.
+
 
 %clean
 


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

end of thread, other threads:[~2021-05-24 20:20 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-11 10:24 [BUG] Weird _expand & _complete behavior for $parameters in "double quotes" Marlon Richert
2021-05-11 11:05 ` Bart Schaefer
2021-05-11 17:32   ` Marlon Richert
2021-05-11 19:40     ` Bart Schaefer
2021-05-12  6:43       ` Marlon Richert
2021-05-23 21:02     ` Lawrence Velázquez
2021-05-24 20:13       ` Bart Schaefer
2021-05-24 20:19         ` Daniel Shahaf

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).