Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: RC_QUOTES word splitting fix



With the RC_QUOTES option set, ${(z)...} and anything that used the same
mechanism caused

'stuff '' more stuff'

to turn into

'stuff ' more stuff'

in the split words.  The quotes should be left alone at this stage.

The fix is easy: as the split words are the only result of the lexical
analysis we care about here, we can just turn off RC_QUOTES temporarily
for the operation.  It looks to the lexical analyser like two strings
stuck together, which happens to work fine since we keep all the
quotes.

Index: Src/hist.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/hist.c,v
retrieving revision 1.103
diff -p -u -r1.103 hist.c
--- Src/hist.c	6 Oct 2010 13:07:44 -0000	1.103
+++ Src/hist.c	6 Oct 2010 13:16:59 -0000
@@ -2368,15 +2368,6 @@ readhistfile(char *fn, int err, int read
 			if (!strcmp(word, ";"))
 			    continue;
 			while (*pt) {
-			    /*
-			     * Oddity 3: "'"s can turn out differently
-			     * if RC_QUOTES is in use.
-			     */
-			    if (*pt == '\'' && pt > start &&
-				pt[-1] == '\'' && word[-1] == '\'') {
-				pt++;
-				continue;
-			    }
 			    if (!*word) {
 				bad = 1;
 				break;
@@ -2887,12 +2878,18 @@ bufferwords(LinkList list, char *buf, in
     int num = 0, cur = -1, got = 0, ne = noerrs;
     int owb = wb, owe = we, oadx = addedx, ozp = zleparse, onc = nocomments;
     int ona = noaliases, ocs = zlemetacs, oll = zlemetall;
-    int forloop = 0;
+    int forloop = 0, rcquotes = opts[RCQUOTES];
     char *p, *addedspaceptr;
 
     if (!list)
 	list = newlinklist();
 
+    /*
+     * With RC_QUOTES, 'foo '' bar' comes back as 'foo ' bar'.  That's
+     * not very useful.  As nothing in here requires the fully processed
+     * string expression, we just turn the option off for this function.
+     */
+    opts[RCQUOTES] = 0;
     zleparse = 1;
     addedx = 0;
     noerrs = 1;
@@ -3095,6 +3092,7 @@ bufferwords(LinkList list, char *buf, in
     wb = owb;
     we = owe;
     addedx = oadx;
+    opts[RCQUOTES] = rcquotes;
 
     if (index)
 	*index = cur;

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