Skip to content

Commit

Permalink
auto merge of #20238 : barosl/rust/regex-repeater-panic, r=huonw
Browse files Browse the repository at this point in the history
This bug has also affected the `regex!` macro, which has caused an ICE when such an invalid expression is provided.

Fixes #20208.
  • Loading branch information
bors committed Dec 27, 2014
2 parents 16e4fef + 0bd8534 commit 9be54be
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/libregex/parse.rs
Expand Up @@ -320,9 +320,10 @@ impl<'a> Parser<'a> {
}

fn push_repeater(&mut self, c: char) -> Result<(), Error> {
if self.stack.len() == 0 {
return self.err(
"A repeat operator must be preceded by a valid expression.")
match self.stack.last() {
Some(&Expr(..)) => (),
// self.stack is empty, or the top item is not an Expr
_ => return self.err("A repeat operator must be preceded by a valid expression."),
}
let rep: Repeater = match c {
'?' => ZeroOne, '*' => ZeroMore, '+' => OneMore,
Expand Down
1 change: 1 addition & 0 deletions src/libregex/test/tests.rs
Expand Up @@ -142,6 +142,7 @@ noparse!{fail_range_end_no_class, "[a-[:lower:]]"}
noparse!{fail_range_end_no_begin, r"[a-\A]"}
noparse!{fail_range_end_no_end, r"[a-\z]"}
noparse!{fail_range_end_no_boundary, r"[a-\b]"}
noparse!{fail_repeat_no_expr, r"-|+"}

macro_rules! mat {
($name:ident, $re:expr, $text:expr, $($loc:tt)+) => (
Expand Down

0 comments on commit 9be54be

Please sign in to comment.