Merge #396
396: Fix the `panic` found whilst fuzzing r=matklad,me a=DJMcNab This occurred when a non-ascii character was used in an ascii escape, for example in the motivating example: `if'\xɿ`, which can be further simplified to `'\xɿ`. Co-authored-by: DJMcNab <36049421+djmcnab@users.noreply.github.com>
This commit is contained in:
commit
5a866a772c
@ -89,12 +89,17 @@ pub(super) fn is_ascii_escape(code: char) -> bool {
|
||||
|
||||
fn validate_ascii_code_escape(text: &str, range: TextRange, errors: &mut Vec<SyntaxError>) {
|
||||
// An AsciiCodeEscape has 4 chars, example: `\xDD`
|
||||
if text.len() < 4 {
|
||||
if !text.is_ascii() {
|
||||
// TODO: Give a more precise error message (say what the invalid character was)
|
||||
errors.push(SyntaxError::new(AsciiCodeEscapeOutOfRange, range));
|
||||
} else if text.chars().count() < 4 {
|
||||
errors.push(SyntaxError::new(TooShortAsciiCodeEscape, range));
|
||||
} else {
|
||||
assert!(
|
||||
text.chars().count() == 4,
|
||||
"AsciiCodeEscape cannot be longer than 4 chars"
|
||||
assert_eq!(
|
||||
text.chars().count(),
|
||||
4,
|
||||
"AsciiCodeEscape cannot be longer than 4 chars, but text '{}' is",
|
||||
text,
|
||||
);
|
||||
|
||||
match u8::from_str_radix(&text[2..], 16) {
|
||||
|
1
crates/ra_syntax/tests/data/parser/fuzz-failures/0003.rs
Normal file
1
crates/ra_syntax/tests/data/parser/fuzz-failures/0003.rs
Normal file
@ -0,0 +1 @@
|
||||
if'\xɿ
|
Loading…
Reference in New Issue
Block a user