zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: ${(z)...} with error
@ 2002-06-14 13:14 Peter Stephenson
  2002-06-14 13:18 ` Peter Stephenson
  0 siblings, 1 reply; 5+ messages in thread
From: Peter Stephenson @ 2002-06-14 13:14 UTC (permalink / raw)
  To: Zsh hackers list

If a ${(z)...} aborts early, the space we added at the end for the lexer
to be able to spot the end of the last word isn't stripped, so we end up
returning a final string with a bogus space at the end.

It's hard to know if there are pathological cases, however.  I think
this is better than it was before, but it may well not be perfect.

It would actually be quite nice to indicate to the user a lexical error
in the last word, but it's hard to pass back.

Index: Src/hist.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/hist.c,v
retrieving revision 1.44
diff -u -r1.44 hist.c
--- Src/hist.c	24 Mar 2002 23:52:47 -0000	1.44
+++ Src/hist.c	14 Jun 2002 13:13:04 -0000
@@ -2291,7 +2291,16 @@
 	}
     } while (tok != ENDINPUT && tok != LEXERR);
     if (buf && tok == LEXERR && tokstr && *tokstr) {
+	int plen;
 	untokenize((p = dupstring(tokstr)));
+	plen = strlen(p);
+	/*
+	 * Strip the space we added for lexing but which won't have
+	 * been swallowed by the lexer because we aborted early.
+	 * The test is paranoia.
+	 */
+	if (plen && p[plen-1] == ' ' && (plen == 1 || p[plen-2] != Meta))
+	    p[plen - 1] = '\0';
 	addlinknode(list, p);
 	num++;
     }

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 392070


**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential 
and/or privileged material. 
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by 
persons or entities other than the intended recipient is 
prohibited.  
If you received this in error, please contact the sender and 
delete the material from any computer.
**********************************************************************


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

end of thread, other threads:[~2002-06-14 16:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-06-14 13:14 PATCH: ${(z)...} with error Peter Stephenson
2002-06-14 13:18 ` Peter Stephenson
2002-06-14 13:32   ` Borsenkow Andrej
2002-06-14 13:40     ` Borsenkow Andrej
2002-06-14 16:29   ` 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).