Make byte/unicode escapes with no digits a tokenizer error

This is the simple fix - if we have no valid digit, we have nothing to
return. So instead of returning a NULL, we return an error.

This is already the case for invalid octal escapes (like `\777`).

Fixes #8545
This commit is contained in:
Fabian Homborg 2022-03-03 12:12:04 +01:00
parent 02c34a30eb
commit f284cdce5b
2 changed files with 13 additions and 1 deletions

View File

@ -1219,6 +1219,8 @@ maybe_t<size_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<size_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<wchar_t>((byte_literal ? ENCODE_DIRECT_BASE : 0) + res);
} else {

View File

@ -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: ^