Skip to content

Commit

Permalink
syntax: include only the start of the character class on error
Browse files Browse the repository at this point in the history
This fixes a bug where the caret in some types of error messages was not
quite correct.

Fixes #792, Closes #794
  • Loading branch information
alexfertel authored and BurntSushi committed Jul 5, 2022
1 parent fbbca38 commit 4b057a7
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions regex-syntax/src/ast/parse.rs
Expand Up @@ -1927,7 +1927,7 @@ impl<'s, P: Borrow<Parser>> ParserI<'s, P> {
}));
if !self.bump_and_bump_space() {
return Err(self.error(
Span::new(start, self.pos()),
Span::new(start, start),
ast::ErrorKind::ClassUnclosed,
));
}
Expand Down Expand Up @@ -5515,14 +5515,23 @@ bar
assert_eq!(
parser("[-").parse_set_class_open().unwrap_err(),
TestError {
span: span(0..2),
span: span(0..0),
kind: ast::ErrorKind::ClassUnclosed,
}
);
assert_eq!(
parser("[--").parse_set_class_open().unwrap_err(),
TestError {
span: span(0..3),
span: span(0..0),
kind: ast::ErrorKind::ClassUnclosed,
}
);

// See: https://github.com/rust-lang/regex/issues/792
assert_eq!(
parser("(?x)[-#]").parse_with_comments().unwrap_err(),
TestError {
span: span(4..4),
kind: ast::ErrorKind::ClassUnclosed,
}
);
Expand Down

0 comments on commit 4b057a7

Please sign in to comment.