1379e36
From 9a763dd9b9b88f9c8cd235fddfda839c6b7971cb Mon Sep 17 00:00:00 2001
1379e36
From: christos <christos>
1379e36
Date: Tue, 8 Mar 2016 15:45:26 +0000
9757dff
Subject: [PATCH 1/4] PR/526: David Kaspar: Quote backslashes properly so that they
1379e36
 can be preserved in `` expansions.
1379e36
1379e36
---
1379e36
 Fixes     | 2 ++
1379e36
 sh.glob.c | 4 +++-
1379e36
 sh.lex.c  | 2 +-
1379e36
 3 files changed, 6 insertions(+), 2 deletions(-)
1379e36
1379e36
diff --git a/Fixes b/Fixes
1379e36
index 1fe33e8..b182f1a 100644
1379e36
--- a/Fixes
1379e36
+++ b/Fixes
1379e36
@@ -1,3 +1,5 @@
1379e36
+ 10. PR/526: Quote backslashes properly so they can be preserved in ``
1379e36
+     expansions
1379e36
   9. Fix memory leak for paraml
1379e36
   8. Add notempty and ask values for the noclobber setting (Martin Tournoij)
1379e36
   7. more correct $wordchars for vimode (Luke Mewburn)
1379e36
diff --git a/sh.glob.c b/sh.glob.c
1379e36
index dce0217..895a603 100644
1379e36
--- a/sh.glob.c
1379e36
+++ b/sh.glob.c
1379e36
@@ -878,7 +878,9 @@ backeval(struct blk_buf *bb, struct Strbuf *word, Char *cp, int literal)
1379e36
 	    if (!quoted && (c == ' ' || c == '\t'))
1379e36
 		break;
1379e36
 	    cnt++;
1379e36
-	    Strbuf_append1(word, c | quoted);
1379e36
+	    if (c == '\\' || quoted)
1379e36
+		c |= QUOTE;
1379e36
+	    Strbuf_append1(word, c);
1379e36
 	}
1379e36
 	/*
1379e36
 	 * Unless at end-of-file, we will form a new word here if there were
1379e36
diff --git a/sh.lex.c b/sh.lex.c
1379e36
index 8a6d1b0..eae8a03 100644
1379e36
--- a/sh.lex.c
1379e36
+++ b/sh.lex.c
1379e36
@@ -386,7 +386,7 @@ loop:
1379e36
 			     */
1379e36
 			    c |= QUOTE;
1379e36
 			ungetC(c);
1379e36
-			c = '\\';
1379e36
+			c = '\\' | QUOTE;
1379e36
 		    }
1379e36
 		}
1379e36
 	    }
1379e36
-- 
1379e36
2.5.5
1379e36
4fa96ac
4fa96ac
From d52d669405da2fce61bd04bf80915e2e6ac5e842 Mon Sep 17 00:00:00 2001
4fa96ac
From: christos <christos>
4fa96ac
Date: Fri, 13 May 2016 15:08:12 +0000
9757dff
Subject: [PATCH 2/4] PR/526: Now that backslashes are quoted, we don't need to
4fa96ac
 handle them specially here. Fixes echo '\n'<enter><ctrl-p> displaying echo
4fa96ac
 '\\n'.
4fa96ac
4fa96ac
---
4fa96ac
 tc.func.c | 3 +--
4fa96ac
 1 file changed, 1 insertion(+), 2 deletions(-)
4fa96ac
4fa96ac
diff --git a/tc.func.c b/tc.func.c
4fa96ac
index f2b1a97..97eda4e 100644
4fa96ac
--- a/tc.func.c
4fa96ac
+++ b/tc.func.c
4fa96ac
@@ -120,8 +120,7 @@ expand_lex(const struct wordent *sp0, int from, int to)
4fa96ac
 		if ((*s & QUOTE)
4fa96ac
 		    && (((*s & TRIM) == HIST && HIST != '\0') ||
4fa96ac
 			(((*s & TRIM) == '\'') && (prev_c != '\\')) ||
4fa96ac
-			(((*s & TRIM) == '\"') && (prev_c != '\\')) ||
4fa96ac
-			(((*s & TRIM) == '\\') && (prev_c != '\\')))) {
4fa96ac
+			(((*s & TRIM) == '\"') && (prev_c != '\\')))) {
4fa96ac
 		    Strbuf_append1(&buf, '\\');
4fa96ac
 		}
4fa96ac
 #if INVALID_BYTE != 0
4fa96ac
-- 
4fa96ac
2.5.5
4fa96ac
4fa96ac
4fa96ac
From b1534dd442e5c1c6d662ea73d3324e10708790ff Mon Sep 17 00:00:00 2001
4fa96ac
From: christos <christos>
4fa96ac
Date: Fri, 13 May 2016 15:08:54 +0000
9757dff
Subject: [PATCH 3/4] History expansion fix.
4fa96ac
4fa96ac
---
4fa96ac
 Fixes | 1 +
4fa96ac
 1 file changed, 1 insertion(+)
4fa96ac
4fa96ac
diff --git a/Fixes b/Fixes
4fa96ac
index 8962302..ac899dd 100644
4fa96ac
--- a/Fixes
4fa96ac
+++ b/Fixes
4fa96ac
@@ -1,3 +1,4 @@
4fa96ac
+ 12. PR/526: Fix double \\ printing from previous fix in history expansion.
4fa96ac
  10. PR/526: Quote backslashes properly so they can be preserved in ``
4fa96ac
      expansions
4fa96ac
   9. Fix memory leak for paraml
4fa96ac
-- 
4fa96ac
2.5.5
4fa96ac
9757dff
9757dff
From 819ab9146f10a3eae77098769210e1751cb7d494 Mon Sep 17 00:00:00 2001
9757dff
From: christos <christos>
9757dff
Date: Tue, 24 May 2016 19:29:19 +0000
9757dff
Subject: [PATCH 4/4]  set myvar=`\echo 1 2 3`
9757dff
                    and
9757dff
                      set myvar=`echo 1 2 3`
9757dff
                    should produce the same result for:
9757dff
                      $ echo ${myvar[1]}
9757dff
                      1
9757dff
9757dff
Don't treat the first character of the string specially. If the whole string
9757dff
is quoted, then we are quoted, otherwise not.
9757dff
---
9757dff
 sh.glob.c | 7 ++++++-
9757dff
 1 file changed, 6 insertions(+), 1 deletion(-)
9757dff
9757dff
diff --git a/sh.glob.c b/sh.glob.c
9757dff
index 895a603..8279802 100644
9757dff
--- a/sh.glob.c
9757dff
+++ b/sh.glob.c
9757dff
@@ -708,7 +708,12 @@ backeval(struct blk_buf *bb, struct Strbuf *word, Char *cp, int literal)
9757dff
 
9757dff
     hadnl = 0;
9757dff
     icnt = 0;
9757dff
-    quoted = (literal || (cp[0] & QUOTE)) ? QUOTE : 0;
9757dff
+    if (!literal) {
9757dff
+	for (ip = cp; (*ip & QUOTE) != 0; ip++)
9757dff
+		continue;
9757dff
+	quoted = *ip == '\0';
9757dff
+    } else
9757dff
+	quoted = literal;
9757dff
     faket.t_dtyp = NODE_COMMAND;
9757dff
     faket.t_dflg = F_BACKQ;
9757dff
     faket.t_dlef = 0;
9757dff
-- 
9757dff
2.5.5
9757dff