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 +++++++++--- crates/ra_syntax/tests/data/parser/fuzz-failures/0003.rs | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 crates/ra_syntax/tests/data/parser/fuzz-failures/0003.rs (limited to 'crates/ra_syntax') 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) { 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 -- cgit v1.2.3 From 0fd87cbc478427296f2ca81c177e32bdb41aa133 Mon Sep 17 00:00:00 2001 From: DJMcNab <36049421+DJMcNab@users.noreply.github.com> Date: Tue, 1 Jan 2019 11:10:08 +0000 Subject: Use an else if --- crates/ra_syntax/src/validation/char.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'crates/ra_syntax') diff --git a/crates/ra_syntax/src/validation/char.rs b/crates/ra_syntax/src/validation/char.rs index 3b1b91230..1d6fe8837 100644 --- a/crates/ra_syntax/src/validation/char.rs +++ b/crates/ra_syntax/src/validation/char.rs @@ -92,12 +92,11 @@ fn validate_ascii_code_escape(text: &str, range: TextRange, errors: &mut Vec