diff --git a/regex-syntax/src/parser.rs b/regex-syntax/src/parser.rs index 1d10572..ed9f33b 100644 --- a/regex-syntax/src/parser.rs +++ b/regex-syntax/src/parser.rs @@ -596,7 +596,17 @@ impl Parser { Ok(Build::Expr(if self.flags.unicode { Expr::Class(class) } else { - Expr::ClassBytes(class.to_byte_class()) + let byte_class = class.to_byte_class(); + + // If `class` was only non-empty due to multibyte characters, the + // corresponding byte class will now be empty. + // + // See https://github.com/rust-lang-nursery/regex/issues/303 + if byte_class.is_empty() { + return Err(self.err(ErrorKind::EmptyClass)); + } + + Expr::ClassBytes(byte_class) })) } diff --git a/tests/bytes.rs b/tests/bytes.rs index 73b8b2b..c950688 100644 --- a/tests/bytes.rs +++ b/tests/bytes.rs @@ -53,3 +53,9 @@ matiter!(invalidutf8_anchor3, r"^|ddp\xff\xffdddddlQd@\x80", R(b"\x8d#;\x1a\xa4s3\x05foobarX\\\x0f0t\xe4\x9b\xa4"), (0, 0)); + +// See https://github.com/rust-lang-nursery/regex/issues/303 +#[test] +fn negated_full_byte_range() { + assert!(::regex::bytes::Regex::new(r#"[^\x00-\xff]"#).is_err()); +}