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

Re: Test version before zsh 5.4



Op 03-08-17 om 18:00 schreef Martijn Dekker:
> I found a problem with the shell's generation of C-style shell-quoted
> strings ($'...').
> 
> % testvar=$'one\\two\n'
> breedzicht% set|grep ^testvar
> testvar=$'one\two\n'
> 
> The backslash is not escaped properly.

A simple fix is attached.

- M.
diff --git a/Src/utils.c b/Src/utils.c
index 1b80e8c..5055d69 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -5119,7 +5119,7 @@ niceztrlen(char const *s)
  * If flags contains NICEFLAG_HEAP, use the heap for *outstrp, else
  * zalloc.
  * If flags contsins NICEFLAG_QUOTE, the output is going to be within
- * $'...', so quote "'" with a backslash.
+ * $'...', so quote "'" and "\" with a backslash.
  */
 
 /**/
@@ -5175,6 +5175,10 @@ mb_niceformat(const char *s, FILE *stream, char **outstrp, int flags)
 		fmt = "\\'";
 		newl = 2;
 	    }
+	    else if (c == L'\\' && (flags & NICEFLAG_QUOTE)) {
+		fmt = "\\\\";
+		newl = 2;
+	    }
 	    else
 		fmt = wcs_nicechar_sel(c, &newl, NULL, flags & NICEFLAG_QUOTE);
 	    break;


Messages sorted by: Reverse Date, Date, Thread, Author