Skip to content

fix(fluent-syntax): Don't panic on invalid unicode escape before multi-byte char - #409

Open
onnimonni wants to merge 1 commit into
projectfluent:mainfrom
onnimonni:fix-unicode-escape-panic
Open

onnimonni wants to merge 1 commit into
projectfluent:mainfrom
onnimonni:fix-unicode-escape-panic

Conversation

@onnimonni

Copy link
Copy Markdown

Fixes #389.

skip_unicode_escape_sequence builds its error message by slicing to self.ptr + 1, one byte past the hex digits. If the next character is multi-byte, that's inside it and Slice::slice panics:

fluent_syntax::parser::parse(r#"a = {"\uǔ"}"#); // end byte index 9 is not a char boundary

#389's repro is the same path: \u followed by a combining caron (U+030C).

The fix takes the whole next character instead, so the error now names it (InvalidUnicodeEscapeSequence("ǔ"), matching what the JS parser prints). ASCII and end-of-input behave as before.

Added tests/invalid_unicode_escape.rs covering \u/\U, 2- and 4-byte characters, unterminated input, parse/parse_runtime and &str/String. It panics without the fix. cargo test -p fluent-syntax, cargo fmt --check and clippy pass.

…i-byte char

The error path sliced one byte past the hex digits, which lands inside the
next character when it is multi-byte. Include the whole character instead.

Fixes projectfluent#389
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Panic in FluentResource::try_new

1 participant