diff options
author | ridiculousfish <corydoras@ridiculousfish.com> | 2015-01-15 11:21:07 -0800 |
---|---|---|
committer | ridiculousfish <corydoras@ridiculousfish.com> | 2015-01-15 11:21:07 -0800 |
commit | d4eded2376706c67b680ad522e61cbe54d8214b0 (patch) | |
tree | b213eebdde9183a2b36c33d61a2ba6dcbcb81a27 /builtin_printf.cpp | |
parent | 20974edc14f43822084bf584c3d19fe23e80247b (diff) |
Make octal/hex escapes in printf and echo output literal bytes
Fixes #1894
Diffstat (limited to 'builtin_printf.cpp')
-rw-r--r-- | builtin_printf.cpp | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/builtin_printf.cpp b/builtin_printf.cpp index f77a3a72..916166b0 100644 --- a/builtin_printf.cpp +++ b/builtin_printf.cpp @@ -357,16 +357,17 @@ long builtin_printf_state_t::print_esc(const wchar_t *escstart, bool octal_0) esc_value = esc_value * 16 + hex_to_bin(*p); if (esc_length == 0) this->fatal_error(_(L"missing hexadecimal number in escape")); - this->append_output(esc_value); + this->append_output(ENCODE_DIRECT_BASE + esc_value % 256); } else if (is_octal_digit(*p)) { /* Parse \0ooo (if octal_0 && *p == L'0') or \ooo (otherwise). Allow \ooo if octal_0 && *p != L'0'; this is an undocumented extension to POSIX that is compatible with Bash 2.05b. */ + /* Wrap mod 256, which matches historic behavior */ for (esc_length = 0, p += octal_0 && *p == L'0'; esc_length < 3 && is_octal_digit(*p); ++esc_length, ++p) esc_value = esc_value * 8 + octal_to_bin(*p); - this->append_output(esc_value); + this->append_output(ENCODE_DIRECT_BASE + esc_value % 256); } else if (*p && wcschr(L"\"\\abcefnrtv", *p)) { |