Skip to content

Commit 4b057a7

Browse files
alexfertelBurntSushi
authored andcommitted
syntax: include only the start of the character class on error
This fixes a bug where the caret in some types of error messages was not quite correct. Fixes #792, Closes #794
1 parent fbbca38 commit 4b057a7

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

Diff for: regex-syntax/src/ast/parse.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -1927,7 +1927,7 @@ impl<'s, P: Borrow<Parser>> ParserI<'s, P> {
19271927
}));
19281928
if !self.bump_and_bump_space() {
19291929
return Err(self.error(
1930-
Span::new(start, self.pos()),
1930+
Span::new(start, start),
19311931
ast::ErrorKind::ClassUnclosed,
19321932
));
19331933
}
@@ -5515,14 +5515,23 @@ bar
55155515
assert_eq!(
55165516
parser("[-").parse_set_class_open().unwrap_err(),
55175517
TestError {
5518-
span: span(0..2),
5518+
span: span(0..0),
55195519
kind: ast::ErrorKind::ClassUnclosed,
55205520
}
55215521
);
55225522
assert_eq!(
55235523
parser("[--").parse_set_class_open().unwrap_err(),
55245524
TestError {
5525-
span: span(0..3),
5525+
span: span(0..0),
5526+
kind: ast::ErrorKind::ClassUnclosed,
5527+
}
5528+
);
5529+
5530+
// See: https://github.com/rust-lang/regex/issues/792
5531+
assert_eq!(
5532+
parser("(?x)[-#]").parse_with_comments().unwrap_err(),
5533+
TestError {
5534+
span: span(4..4),
55265535
kind: ast::ErrorKind::ClassUnclosed,
55275536
}
55285537
);

0 commit comments

Comments
 (0)