Skip to content

Commit 524ba8e

Browse files
committed
Add a test case for fix #304.
1 parent 31af886 commit 524ba8e

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

regex-syntax/src/parser.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,18 +591,20 @@ impl Parser {
591591
}
592592
class = self.class_transform(negated, class).canonicalize();
593593
if class.is_empty() {
594+
// e.g., [^\d\D]
594595
return Err(self.err(ErrorKind::EmptyClass));
595596
}
596597
Ok(Build::Expr(if self.flags.unicode {
597598
Expr::Class(class)
598599
} else {
599600
let byte_class = class.to_byte_class();
600601

601-
// If `class` was only non-empty due to multibyte characters, the
602+
// If `class` was only non-empty due to multibyte characters, the
602603
// corresponding byte class will now be empty.
603604
//
604605
// See https://github.com/rust-lang-nursery/regex/issues/303
605606
if byte_class.is_empty() {
607+
// e.g., (?-u)[^\x00-\xFF]
606608
return Err(self.err(ErrorKind::EmptyClass));
607609
}
608610

@@ -2757,6 +2759,9 @@ mod tests {
27572759
test_err!("[]", 2, ErrorKind::UnexpectedClassEof);
27582760
test_err!("[^]", 3, ErrorKind::UnexpectedClassEof);
27592761
test_err!(r"[^\d\D]", 7, ErrorKind::EmptyClass);
2762+
2763+
let flags = Flags { allow_bytes: true, .. Flags::default() };
2764+
test_err!(r"(?-u)[^\x00-\xFF]", 17, ErrorKind::EmptyClass, flags);
27602765
}
27612766

27622767
#[test]

0 commit comments

Comments
 (0)