diff --git a/src/common.cpp b/src/common.cpp index ccd8d803d..38313c6c2 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -1219,6 +1219,8 @@ maybe_t read_unquoted_escape(const wchar_t *input, wcstring *result, boo for (size_t i = 0; i < chars; i++) { long d = convert_digit(input[in_pos], base); if (d < 0) { + // If we have no digit, this is a tokenizer error. + if (i == 0) errored = true; break; } @@ -1226,7 +1228,7 @@ maybe_t read_unquoted_escape(const wchar_t *input, wcstring *result, boo in_pos++; } - if (res <= max_val) { + if (!errored && res <= max_val) { result_char_or_none = static_cast((byte_literal ? ENCODE_DIRECT_BASE : 0) + res); } else { diff --git a/tests/checks/basic.fish b/tests/checks/basic.fish index 3befee0ed..cfade8f88 100644 --- a/tests/checks/basic.fish +++ b/tests/checks/basic.fish @@ -558,3 +558,13 @@ end # CHECKERR: for PWD in foo bar # CHECKERR: ^ # XXX FIXME carat should point at PWD + +$fish -c 'echo \xtest' +# CHECKERR: fish: Invalid token '\xtest' +# CHECKERR: echo \xtest +# CHECKERR: ^ + +$fish -c 'echo \utest' +# CHECKERR: fish: Invalid token '\utest' +# CHECKERR: echo \utest +# CHECKERR: ^