zsh-workers
 help / color / mirror / code / Atom feed
* Anybody know what's going on here in _expand?  Patch?
@ 2013-12-27  1:08 Bart Schaefer
  2013-12-27 15:08 ` Jun T.
  0 siblings, 1 reply; 2+ messages in thread
From: Bart Schaefer @ 2013-12-27  1:08 UTC (permalink / raw)
  To: zsh-workers

Line numbers for reference:

103 # Now try globbing.
104 
105 [[ "$force" = *g* ]] || zstyle -T ":completion:${curcontext}:" glob &&
106     eval 'exp=( ${~exp//(#b)\\[         
107 ]/$match[1]} ); exp=( ${(q)exp} )' 2>/dev/null

There is a trailing space and tab on line 106.

That stuff starting with //(#b) appears to want to replace any
whitespace that is preceded by a backslash with *something*, but as
there are no parens for the $match array to refer to, it ends up simply
removing the whitespace (along with the backslash), at least as far as I
can tell.  That can't be correct ...?

A bit further up is this:

 89   eval 'exp=( ${${(e)exp//\\[   
 90 ]/ }//(#b)([    
 91 ])/\\$match[1]} )' 2>/dev/null

That looks pretty similar (trailing space+tab on both lines 89 and 90)
except there it's turning backslash-whitespace into just a space, and
then adding back the backslash to any space that appears after applying
the (e) flag.

As it turns out, that eval on line 106 is where Yuri D'Elia's examples
[from the "Expanding quotes" thread over on zsh-users] go wrong. Adding
quote marks as well as whitespace to the character class on 106 "fixes"
both examples.

If nobody can explain what's correct about lines 106 and 107 as is,
then I propose the following patch, which adds the seemingly missing
backreference parens as well as putting quote chars in the class.


diff --git a/Completion/Base/Completer/_expand b/Completion/Base/Completer/_expand
index 44954a2..e52144c 100644
--- a/Completion/Base/Completer/_expand
+++ b/Completion/Base/Completer/_expand
@@ -103,8 +103,8 @@ subd=("$exp[@]")
 # Now try globbing.
 
 [[ "$force" = *g* ]] || zstyle -T ":completion:${curcontext}:" glob &&
-    eval 'exp=( ${~exp//(#b)\\[ 	
-]/$match[1]} ); exp=( ${(q)exp} )' 2>/dev/null
+    eval 'exp=( ${~exp//(#b)\\([ 	\"'"\'"'
+])/$match[1]} ); exp=( ${(q)exp} )' 2>/dev/null
 
 ### Don't remember why we once used this instead of the (q) above.
 #    eval 'exp=( ${~exp} ); exp=( ${exp//(#b)([][()|*?^#~<>\\=])/\\${match[1]}} )' 2>/dev/null


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

* Re: Anybody know what's going on here in _expand?  Patch?
  2013-12-27  1:08 Anybody know what's going on here in _expand? Patch? Bart Schaefer
@ 2013-12-27 15:08 ` Jun T.
  0 siblings, 0 replies; 2+ messages in thread
From: Jun T. @ 2013-12-27 15:08 UTC (permalink / raw)
  To: zsh-workers

> then I propose the following patch, which adds the seemingly missing
> backreference parens as well as putting quote chars in the class.

I believe the lack of the backreference paren is definitely a bug.

I guess the reason that this seemingly-rather-serious bug has not
been noticed so far is:

match[1] is set at lines 90-91 (where the pattern has a correct
pair of back-reference parentheses), and its value is NOT rest at
line 106 (where there are no back-reference parentheses).
The value is re-used at line 107, and in many (or all?) cases the
value is correct (a single space for most of the cases).


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

end of thread, other threads:[~2013-12-27 15:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-27  1:08 Anybody know what's going on here in _expand? Patch? Bart Schaefer
2013-12-27 15:08 ` Jun T.

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