mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 21:33:09 +00:00
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:
parent
02c34a30eb
commit
f284cdce5b
2 changed files with 13 additions and 1 deletions
|
@ -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 {
|
||||
|
|
|
@ -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: ^
|
||||
|
|
Loading…
Reference in a new issue