@@ -1686,12 +1686,17 @@ _rmescapes(char *str, int flag)
}
if (*p == (char)CTLESC) {
p++;
- if (notescaped)
- *q++ = '\\';
- } else if (*p == '\\' && !inquotes) {
- /* naked back slash */
- notescaped = 0;
- goto copy;
+ goto escape;
+ } else if (*p == '\\') {
+ if (inquotes) {
+escape:
+ if (notescaped)
+ *q++ = '\\';
+ } else {
+ /* naked back slash */
+ notescaped = 0;
+ goto copy;
+ }
}
notescaped = globbing;
copy:
@@ -944,6 +944,9 @@ readtoken1(int firstc, char const *syntax, char *eofmark, int striptabs)
eofmark != NULL
)
) {
+ /* Reserve extra memory in case this backslash will require later escaping. */
+ USTPUTC(CTLQUOTEMARK, out);
+ USTPUTC(CTLQUOTEMARK, out);
USTPUTC('\\', out);
}
USTPUTC(CTLESC, out);