Skip to content

Commit

Permalink
Fix panic in parser
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewhickman committed Jun 25, 2023
1 parent 75a5995 commit f14886a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## Fixed

- Fixed a panic while parsing an invalid file like `{ $`.

## [0.4.0] - 2023-06-18

## Changed
Expand Down
5 changes: 4 additions & 1 deletion protox-parse/src/parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1162,9 +1162,12 @@ impl<'a> Parser<'a> {
match self.peek() {
Ok(None) => return,
Ok(Some((tok, _))) if tokens.contains(&tok) => return,
_ => {
Ok(Some(_)) => {
self.bump();
}
Err(()) => {
self.peek = None;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
source: protox-parse/src/parse/tests.rs
expression: "if parser.lexer.extras.errors.is_empty() {\n Ok(result.unwrap())\n } else { Err(parser.lexer.extras.errors) }"
---
Err(
[
UnexpectedToken {
expected: "'enum', 'extend', 'import', 'message', 'option', 'service', 'package' or ';'",
found: "thing",
span: 0..5,
},
InvalidToken {
span: 6..7,
},
],
)
1 change: 1 addition & 0 deletions protox-parse/src/parse/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,4 +410,5 @@ pub fn parse_file() {
case!(parse_file("syntax = 1;"));
case!(parse_file("thing"));
case!(parse_file("message } } } message } } }"));
case!(parse_file("thing $"));
}

0 comments on commit f14886a

Please sign in to comment.