}
if ((unsigned char)*p == CTLESC) {
p++;
+#if DEBUG
+ if (*p == '\0')
+ ash_msg_and_raise_error("CTLESC at EOL (shouldn't happen)");
+#endif
if (protect_against_glob) {
*q++ = '\\';
}
USTPUTC(c, out);
break;
case CCTL:
- if (eofmark == NULL || dblquote)
- USTPUTC(CTLESC, out);
#if ENABLE_ASH_BASH_COMPAT
if (c == '\\' && bash_dollar_squote) {
c = decode_dollar_squote();
+ if (c == '\0') {
+ /* skip $'\000', $'\x00' (like bash) */
+ break;
+ }
if (c & 0x100) {
- USTPUTC('\\', out);
+ /* Unknown escape. Encode as '\z' */
+ c = (unsigned char)c;
if (eofmark == NULL || dblquote)
- /* Or else this SEGVs: $'\<0x82>' */
USTPUTC(CTLESC, out);
- c = (unsigned char)c;
+ USTPUTC('\\', out);
}
}
#endif
+ if (eofmark == NULL || dblquote)
+ USTPUTC(CTLESC, out);
USTPUTC(c, out);
break;
case CBACK: /* backslash */
--- /dev/null
+# Embedded NULs
+echo $'str\x00'strstrstrstrstrstrstrstrstrstrstrstrstrstrstrstr
+echo $'str\000'strstrstrstrstrstrstrstrstrstrstrstrstrstrstrstr
+
+# The chars after '\' are hex 0x80,81,82...
+echo 80:$'\\80'
+echo 81:$'\\81'
+echo 82:$'\\82'
+
+echo Done:$?