mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 05:15:04 +00:00
Fix the panic
found whilst fuzzing
This commit is contained in:
parent
81acdafc51
commit
72ab6f7727
2 changed files with 10 additions and 3 deletions
|
@ -89,12 +89,18 @@ pub(super) fn is_ascii_escape(code: char) -> bool {
|
||||||
|
|
||||||
fn validate_ascii_code_escape(text: &str, range: TextRange, errors: &mut Vec<SyntaxError>) {
|
fn validate_ascii_code_escape(text: &str, range: TextRange, errors: &mut Vec<SyntaxError>) {
|
||||||
// An AsciiCodeEscape has 4 chars, example: `\xDD`
|
// An AsciiCodeEscape has 4 chars, example: `\xDD`
|
||||||
|
if !text.is_ascii() {
|
||||||
|
// TODO: Give a more precise error message (say what the invalid character was)
|
||||||
|
errors.push(SyntaxError::new(AsciiCodeEscapeOutOfRange, range));
|
||||||
|
}
|
||||||
if text.len() < 4 {
|
if text.len() < 4 {
|
||||||
errors.push(SyntaxError::new(TooShortAsciiCodeEscape, range));
|
errors.push(SyntaxError::new(TooShortAsciiCodeEscape, range));
|
||||||
} else {
|
} else {
|
||||||
assert!(
|
assert_eq!(
|
||||||
text.chars().count() == 4,
|
text.len(),
|
||||||
"AsciiCodeEscape cannot be longer than 4 chars"
|
4,
|
||||||
|
"AsciiCodeEscape cannot be longer than 4 chars, but text '{}' is",
|
||||||
|
text,
|
||||||
);
|
);
|
||||||
|
|
||||||
match u8::from_str_radix(&text[2..], 16) {
|
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…
Add table
Add a link
Reference in a new issue