Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Bug in banghist-like expansions?
- X-seq: zsh-workers 27780
- From: Peter Stephenson <pws@xxxxxxx>
- To: "Zsh Hackers' List" <zsh-workers@xxxxxxx>
- Subject: Re: Bug in banghist-like expansions?
- Date: Thu, 11 Mar 2010 12:34:58 +0000
- In-reply-to: <20100226232309.4037dc71@pws-pc>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- Organization: CSR
- References: <871vg74vm8.fsf@xxxxxxxxxxxxxxxxxxxxxx> <20100226232309.4037dc71@pws-pc>
On Fri, 26 Feb 2010 23:23:09 +0000
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx> wrote:
> On Fri, 26 Feb 2010 20:58:39 +0100
> Frank Terbeck <ft@xxxxxxxxxxxxxxxxxxx> wrote:
> > zsh% baz=/foo/bar
> > zsh% print ${baz:s/\//l/}
> > zsh: unrecognized modifier
> >>
> > I couldn't find a limitation in the manual about escaping the delimiter
> > in such expansions in `zshexpn(1)'. Is this a bug or am I missing
> > something?
>
> Yes, it is documented that this should work, if you can find it. The :s
> documentation is a bit wayward (and just confused me, too): the full
> explanation is further down the page at the end of the list of
> modifiers.
>
> There are actually four distinct cases to fix.
This (including the follow-up fix for \&) has a knock-on effect that
turned up in a substitution in _files, tickled by completing after "chmod
-x": it affects the way backslashes are handled in the replacement portion
of the substitution. Before, it would halve the backslashes, now it
preserves the number.
I think the new behaviour is a correct logical consequence of the original
fix, on the basis that backslashes should be active in both the source and
replacement text (you can quote the separator in either part). Hence you
would expect a number of quoted backslashes on the left together with the
same number on the right to preserve the number: one \\ on the left is a
real backslash in the text, one \\ on the right is a real backslash in the
text.
Look at the new test and see if you think this is right.
I further put it to the court that twelve backslashes was getting *very*
silly.
(Now I've started myself wondering whether Emacs is going to halve the
number of backslashes when I send the message, so it's time to do something
else.)
Index: Completion/Unix/Type/_files
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Type/_files,v
retrieving revision 1.11
diff -p -u -r1.11 _files
--- Completion/Unix/Type/_files 17 Aug 2009 21:52:10 -0000 1.11
+++ Completion/Unix/Type/_files 11 Mar 2010 12:25:59 -0000
@@ -90,7 +90,7 @@ fi
tried=()
for def in "$pats[@]"; do
- eval "def=( ${${def:gs/\\:/\\\\\\\\\\\\:}//(#b)([][()|*?^#~<>])/\\${match[1]}} )"
+ eval "def=( ${${def:gs/\\:/\\\\\\:}//(#b)([][()|*?^#~<>])/\\${match[1]}} )"
tmp="${(@M)def#*[^\\]:}"
(( $tried[(I)${(q)tmp}] )) && continue
Index: Test/D04parameter.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/D04parameter.ztst,v
retrieving revision 1.39
diff -p -u -r1.39 D04parameter.ztst
--- Test/D04parameter.ztst 27 Feb 2010 00:18:18 -0000 1.39
+++ Test/D04parameter.ztst 11 Mar 2010 12:25:59 -0000
@@ -959,6 +959,25 @@
>oof/rab
>oof/rab
+ bsbs='X\\\\Y'
+ print -r -- ${bsbs:s/\\/\\/}
+ print -r -- "${bsbs:s/\\/\\/}"
+ print -r -- ${bsbs:s/\\\\/\\\\/}
+ print -r -- "${bsbs:s/\\\\/\\\\/}"
+ print -r -- ${bsbs:gs/\\/\\/}
+ print -r -- "${bsbs:gs/\\/\\/}"
+ print -r -- ${bsbs:gs/\\\\/\\\\/}
+ print -r -- "${bsbs:gs/\\\\/\\\\/}"
+0:Handling of backslashed backslashes in substitution modifier
+>X\\\\Y
+>X\\\\Y
+>X\\\\Y
+>X\\\\Y
+>X\\\\Y
+>X\\\\Y
+>X\\\\Y
+>X\\\\Y
+
print -r ${${:-one/two}:s,/,X&Y,}
print -r ${${:-one/two}:s,/,X\&Y,}
print -r ${${:-one/two}:s,/,X\\&Y,}
--
Peter Stephenson <pws@xxxxxxx> Software Engineer
Tel: +44 (0)1223 692070 Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK
Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
Messages sorted by:
Reverse Date,
Date,
Thread,
Author