Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make invalid Unicode escapes a tokenizer error #8545

Closed
krobelus opened this issue Dec 12, 2021 · 2 comments
Closed

Make invalid Unicode escapes a tokenizer error #8545

krobelus opened this issue Dec 12, 2021 · 2 comments

Comments

@krobelus
Copy link
Contributor

krobelus commented Dec 12, 2021

We report a tokenizer error on some invalid escape sequences

$ echo \777
fish: Invalid token '\777'
echo \777
     ^

but on others we silently interpret them as NUL bytes, which breaks many of our internal assumptions.

$ echo \utest

$

The fixes to #8195 fixed resulting issues in autoloading.
We should report a tokenizer error and maybe revert the fixes.

@faho
Copy link
Member

faho commented Feb 24, 2022

A very simple fix would be possible:

fish-shell/src/common.cpp

Lines 1229 to 1234 in 6fcb6f7

if (res <= max_val) {
result_char_or_none =
static_cast<wchar_t>((byte_literal ? ENCODE_DIRECT_BASE : 0) + res);
} else {
errored = true;
}

Make that if (res > 0 && res <= max_val). If no valid unicode escape is read this stays at 0.

That has the side effect of making \x00 an error as well, which is probably correct considering it can't be passed to commands, not even (currently) to builtins. So it causes things like #8468, which we currently answer by saying "don't do that, then", when, as far as I can tell, the only use for these is in string replace -r inside quotes. This could be handled with a flag to indicate NULLs are acceptable.

The error message might need some work (this would error with "invalid token" with no further explanation).

@faho faho closed this as completed in f284cdc Mar 3, 2022
@faho
Copy link
Member

faho commented Mar 3, 2022

I went for the simple fix - escapes with no valid digits are rejected. Other things, including NULLs (which are unusable in most contexts) can be done later.

@zanchey zanchey modified the milestones: fish-future, fish 3.4.0 Mar 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants