zsh-workers
 help / color / mirror / code / Atom feed
* [mpol@charybda.icm.edu.pl: Bug#306346: zsh: replacement seems broken in prompt]
@ 2005-04-26  1:37 Clint Adams
  2005-04-26  3:49 ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Clint Adams @ 2005-04-26  1:37 UTC (permalink / raw)
  To: zsh-workers; +Cc: 306346-forwarded

This is with 21170.

----- Forwarded message from Michal Politowski <mpol@charybda.icm.edu.pl> -----

Date: Tue, 26 Apr 2005 00:01:18 +0200
From: Michal Politowski <mpol@charybda.icm.edu.pl>
To: Debian Bug Tracking System <submit@bugs.debian.org>
Subject: Bug#306346: zsh: replacement seems broken in prompt

4.2.5-4 didn't show this behaviour, so maybe it's the newest patch.
${${foo}/?*/replacement} puts replacement in the prompt even when foo is empty
${foo/?*/replacement} works as expected.

On the command line, echo ${...} works as expected for both expressions,
printing nothing when foo is the empty string.

----- End forwarded message -----


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

* Re: [mpol@charybda.icm.edu.pl: Bug#306346: zsh: replacement seems broken in prompt]
  2005-04-26  1:37 [mpol@charybda.icm.edu.pl: Bug#306346: zsh: replacement seems broken in prompt] Clint Adams
@ 2005-04-26  3:49 ` Bart Schaefer
  2005-04-26  9:44   ` Peter Stephenson
  0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2005-04-26  3:49 UTC (permalink / raw)
  To: zsh-workers; +Cc: 306346-forwarded

On Apr 25,  9:37pm, Clint Adams wrote:
} Subject: [mpol@charybda.icm.edu.pl: Bug#306346: zsh: replacement seems bro
}
} This is with 21170.
} 
} ----- Forwarded message from Michal Politowski <mpol@charybda.icm.edu.pl> -----
} 
} ${${foo}/?*/replacement} puts replacement in the prompt even when foo is empty

Hrm.  This seems to be strictly a promptsubst thing, because

schaefer<505> echo ${${foo}/?*/replacement}

schaefer<506> RPS1='${${foo}/?*/replacement}'
schaefer<507> setopt promptsubst                       ${${foo}/?*/replacement}
schaefer<508>                                                       replacement

Ah, here's an easier way to reproduce it:

schaefer<510> echo "${${foo}/?*/replacement}"
replacement

So it's a quoting thing.

According to GDB, both before and after 21170 the inner ${foo} is
resulting in "\233\0" (which is a Nularg).  After 21170, however, the
comparison against ?* matches this as one character.

The problem is here at line 2344:

2344                        if (pattrylen(p, t, s + l - t, umlen, ioff)) {

And it seems that this is the answer to the question in pattern.c:

    /* inherited from domatch, but why, exactly? */
    if (*string == Nularg)
	string++;

This is precisely the case we're encountering here; it changes the value
of unmetalen within pattryrefs() in a way that we're not changing it
when precomputing it in igetmatch().

What I don't know, though, is whether the Nularg test should be copied
into both igetmatch() and down to by the ztrsub() call in pattryrefs(),
or whether it should simply be

    /* inherited from domatch, but why, exactly? */
    if (*string == Nularg)
	string++, unmetalen--;


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

* Re: [mpol@charybda.icm.edu.pl: Bug#306346: zsh: replacement seems broken in prompt]
  2005-04-26  3:49 ` Bart Schaefer
@ 2005-04-26  9:44   ` Peter Stephenson
  2005-04-26 16:14     ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Stephenson @ 2005-04-26  9:44 UTC (permalink / raw)
  To: zsh-workers, 306346-forwarded

Bart Schaefer wrote:
> What I don't know, though, is whether the Nularg test should be copied
> into both igetmatch() and down to by the ztrsub() call in pattryrefs(),
> or whether it should simply be
> 
>     /* inherited from domatch, but why, exactly? */
>     if (*string == Nularg)
> 	string++, unmetalen--;

I'd be inclined to keep it local and use this fix.  (This can end up
with unmetalen being -2, but that doesn't matter.)  Here's a test, too.

Index: Src/pattern.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/pattern.c,v
retrieving revision 1.25
diff -u -r1.25 pattern.c
--- Src/pattern.c	24 Apr 2005 00:38:15 -0000	1.25
+++ Src/pattern.c	26 Apr 2005 09:40:40 -0000
@@ -1552,8 +1552,10 @@
 	*nump = 0;
     }
     /* inherited from domatch, but why, exactly? */
-    if (*string == Nularg)
+    if (*string == Nularg) {
 	string++;
+	unmetalen--;
+    }
 
     if (stringlen < 0)
 	stringlen = strlen(string);
Index: Test/D04parameter.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/D04parameter.ztst,v
retrieving revision 1.9
diff -u -r1.9 D04parameter.ztst
--- Test/D04parameter.ztst	21 May 2003 16:21:01 -0000	1.9
+++ Test/D04parameter.ztst	26 Apr 2005 09:40:40 -0000
@@ -599,3 +599,8 @@
 >said
 >i
 >willJOYCE
+
+  foo=
+  print "${${foo}/?*/replacement}"
+0:Quoted zero-length strings are handled properly
+>

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

**********************************************************************


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

* Re: [mpol@charybda.icm.edu.pl: Bug#306346: zsh: replacement seems broken in prompt]
  2005-04-26  9:44   ` Peter Stephenson
@ 2005-04-26 16:14     ` Bart Schaefer
  0 siblings, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2005-04-26 16:14 UTC (permalink / raw)
  To: zsh-workers

On Apr 26, 10:44am, Peter Stephenson wrote:
} Subject: Re: [mpol@charybda.icm.edu.pl: Bug#306346: zsh: replacement seems
}
} > or whether it should simply be
} > 
} >     /* inherited from domatch, but why, exactly? */
} 
} I'd be inclined to keep it local and use this fix.

Maybe we should update the comment as well?

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


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

end of thread, other threads:[~2005-04-26 16:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-04-26  1:37 [mpol@charybda.icm.edu.pl: Bug#306346: zsh: replacement seems broken in prompt] Clint Adams
2005-04-26  3:49 ` Bart Schaefer
2005-04-26  9:44   ` Peter Stephenson
2005-04-26 16:14     ` 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).