aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-01-01 11:11:20 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-01-01 11:11:20 +0000
commit5a866a772c863ba7e3ec8bad353c1b6997a7a62a (patch)
treebd7d22f923791d07224720de155aa05efa663f22 /crates/ra_syntax
parent6044ec50572747a1a096133d7f71c2d3d689bbf3 (diff)
parent0fd87cbc478427296f2ca81c177e32bdb41aa133 (diff)
Merge #396
396: Fix the `panic` found whilst fuzzing r=matklad,me a=DJMcNab This occurred when a non-ascii character was used in an ascii escape, for example in the motivating example: `if'\xɿ`, which can be further simplified to `'\xɿ`. Co-authored-by: DJMcNab <[email protected]>
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r--crates/ra_syntax/src/validation/char.rs13
-rw-r--r--crates/ra_syntax/tests/data/parser/fuzz-failures/0003.rs1
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
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.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