From 72ab6f772736f35c53c738735b0c0b4b3f360a20 Mon Sep 17 00:00:00 2001 From: DJMcNab <36049421+DJMcNab@users.noreply.github.com> Date: Mon, 31 Dec 2018 23:02:04 +0000 Subject: Fix the `panic` found whilst fuzzing --- crates/ra_syntax/src/validation/char.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'crates/ra_syntax/src') 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 { fn validate_ascii_code_escape(text: &str, range: TextRange, errors: &mut Vec) { // 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 { errors.push(SyntaxError::new(TooShortAsciiCodeEscape, range)); } else { - assert!( - text.chars().count() == 4, - "AsciiCodeEscape cannot be longer than 4 chars" + assert_eq!( + text.len(), + 4, + "AsciiCodeEscape cannot be longer than 4 chars, but text '{}' is", + text, ); match u8::from_str_radix(&text[2..], 16) { -- cgit v1.2.3