auto merge of #20238 : barosl/rust/regex-repeater-panic, r=huonw

This bug has also affected the `regex!` macro, which has caused an ICE when such an invalid expression is provided.

Fixes #20208.
This commit is contained in:
bors 2014-12-27 09:21:48 +00:00
commit 9be54be15b
2 changed files with 5 additions and 3 deletions

View File

@ -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,

View File

@ -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)+) => (