diff options
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r-- | crates/ra_syntax/src/validation/char.rs | 13 | ||||
-rw-r--r-- | crates/ra_syntax/tests/data/parser/fuzz-failures/0003.rs | 1 |
2 files changed, 10 insertions, 4 deletions
diff --git a/crates/ra_syntax/src/validation/char.rs b/crates/ra_syntax/src/validation/char.rs index 10d3d1dec..1d6fe8837 100644 --- a/crates/ra_syntax/src/validation/char.rs +++ b/crates/ra_syntax/src/validation/char.rs | |||
@@ -89,12 +89,17 @@ pub(super) fn is_ascii_escape(code: char) -> bool { | |||
89 | 89 | ||
90 | fn validate_ascii_code_escape(text: &str, range: TextRange, errors: &mut Vec<SyntaxError>) { | 90 | fn validate_ascii_code_escape(text: &str, range: TextRange, errors: &mut Vec<SyntaxError>) { |
91 | // An AsciiCodeEscape has 4 chars, example: `\xDD` | 91 | // An AsciiCodeEscape has 4 chars, example: `\xDD` |
92 | if text.len() < 4 { | 92 | if !text.is_ascii() { |
93 | // TODO: Give a more precise error message (say what the invalid character was) | ||
94 | errors.push(SyntaxError::new(AsciiCodeEscapeOutOfRange, range)); | ||
95 | } else if text.chars().count() < 4 { | ||
93 | errors.push(SyntaxError::new(TooShortAsciiCodeEscape, range)); | 96 | errors.push(SyntaxError::new(TooShortAsciiCodeEscape, range)); |
94 | } else { | 97 | } else { |
95 | assert!( | 98 | assert_eq!( |
96 | text.chars().count() == 4, | 99 | text.chars().count(), |
97 | "AsciiCodeEscape cannot be longer than 4 chars" | 100 | 4, |
101 | "AsciiCodeEscape cannot be longer than 4 chars, but text '{}' is", | ||
102 | text, | ||
98 | ); | 103 | ); |
99 | 104 | ||
100 | match u8::from_str_radix(&text[2..], 16) { | 105 | match u8::from_str_radix(&text[2..], 16) { |
diff --git a/crates/ra_syntax/tests/data/parser/fuzz-failures/0003.rs b/crates/ra_syntax/tests/data/parser/fuzz-failures/0003.rs new file mode 100644 index 000000000..0f59c4722 --- /dev/null +++ b/crates/ra_syntax/tests/data/parser/fuzz-failures/0003.rs | |||
@@ -0,0 +1 @@ | |||
if'\xɿ \ No newline at end of file | |||