diff options
author | DJMcNab <[email protected]> | 2018-12-31 23:02:04 +0000 |
---|---|---|
committer | DJMcNab <[email protected]> | 2018-12-31 23:02:04 +0000 |
commit | 72ab6f772736f35c53c738735b0c0b4b3f360a20 (patch) | |
tree | dced02be89236888733aab3529aaccaf6c2d9b35 /crates/ra_syntax/src/validation/char.rs | |
parent | 81acdafc518f858db38f1a3d78d9ff498c989176 (diff) |
Fix the `panic` found whilst fuzzing
Diffstat (limited to 'crates/ra_syntax/src/validation/char.rs')
-rw-r--r-- | crates/ra_syntax/src/validation/char.rs | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/crates/ra_syntax/src/validation/char.rs b/crates/ra_syntax/src/validation/char.rs index 10d3d1dec..3b1b91230 100644 --- a/crates/ra_syntax/src/validation/char.rs +++ b/crates/ra_syntax/src/validation/char.rs | |||
@@ -89,12 +89,18 @@ 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.is_ascii() { | ||
93 | // TODO: Give a more precise error message (say what the invalid character was) | ||
94 | errors.push(SyntaxError::new(AsciiCodeEscapeOutOfRange, range)); | ||
95 | } | ||
92 | if text.len() < 4 { | 96 | if text.len() < 4 { |
93 | errors.push(SyntaxError::new(TooShortAsciiCodeEscape, range)); | 97 | errors.push(SyntaxError::new(TooShortAsciiCodeEscape, range)); |
94 | } else { | 98 | } else { |
95 | assert!( | 99 | assert_eq!( |
96 | text.chars().count() == 4, | 100 | text.len(), |
97 | "AsciiCodeEscape cannot be longer than 4 chars" | 101 | 4, |
102 | "AsciiCodeEscape cannot be longer than 4 chars, but text '{}' is", | ||
103 | text, | ||
98 | ); | 104 | ); |
99 | 105 | ||
100 | match u8::from_str_radix(&text[2..], 16) { | 106 | match u8::from_str_radix(&text[2..], 16) { |