Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Notate only the start of the character class on error #794

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion regex-syntax/README.md
Expand Up @@ -53,7 +53,7 @@ for extreme optimization, and therefore, use of `unsafe`.

The standard for using `unsafe` in this crate is extremely high because this
crate is intended to be reasonably safe to use with user supplied regular
expressions. Therefore, while their may be bugs in the regex parser itself,
expressions. Therefore, while there may be bugs in the regex parser itself,
they should _never_ result in memory unsafety unless there is either a bug
in the compiler or the standard library. (Since `regex-syntax` has zero
dependencies.)
Expand Down
2 changes: 1 addition & 1 deletion regex-syntax/src/ast/mod.rs
Expand Up @@ -15,7 +15,7 @@ mod visitor;
/// An error that occurred while parsing a regular expression into an abstract
/// syntax tree.
///
/// Note that note all ASTs represents a valid regular expression. For example,
/// Note that not all ASTs represents a valid regular expression. For example,
/// an AST is constructed without error for `\p{Quux}`, but `Quux` is not a
/// valid Unicode property name. That particular error is reported when
/// translating an AST to the high-level intermediate representation (`HIR`).
Expand Down
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
2 changes: 1 addition & 1 deletion regex-syntax/src/error.rs
Expand Up @@ -182,7 +182,7 @@ impl<'p> Spans<'p> {
if line_count <= 1 { 0 } else { line_count.to_string().len() };
let mut spans = Spans {
pattern: &fmter.pattern,
line_number_width: line_number_width,
line_number_width,
by_line: vec![vec![]; line_count],
multi_line: vec![],
};
Expand Down