aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorDJMcNab <[email protected]>2018-12-31 23:02:04 +0000
committerDJMcNab <[email protected]>2018-12-31 23:02:04 +0000
commit72ab6f772736f35c53c738735b0c0b4b3f360a20 (patch)
treedced02be89236888733aab3529aaccaf6c2d9b35 /crates
parent81acdafc518f858db38f1a3d78d9ff498c989176 (diff)
Fix the `panic` found whilst fuzzing
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_syntax/src/validation/char.rs12
-rw-r--r--crates/ra_syntax/tests/data/parser/fuzz-failures/0003.rs1
2 files changed, 10 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
90fn validate_ascii_code_escape(text: &str, range: TextRange, errors: &mut Vec<SyntaxError>) { 90fn 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) {
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