Auto merge of #15873 - emilio:calc, r=nox

style: Allow trailing whitespace in a calc expression.

This should fix Gecko failures like: https://treeherder.mozilla.org/logviewer.html#?job_id=82470557&repo=autoland&lineNumber=1789

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/15873)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-03-08 08:21:40 -08:00 committed by GitHub
commit 728a249dea
2 changed files with 25 additions and 23 deletions

View file

@ -585,33 +585,32 @@ impl CalcLengthOrPercentage {
products.push(try!(CalcLengthOrPercentage::parse_product(input, expected_unit)));
loop {
let position = input.position();
match input.next_including_whitespace() {
Ok(Token::WhiteSpace(_)) => {
match input.next() {
Ok(Token::Delim('+')) => {
products.push(try!(CalcLengthOrPercentage::parse_product(input, expected_unit)));
let position = input.position();
match input.next_including_whitespace() {
Ok(Token::WhiteSpace(_)) => {
if input.is_exhausted() {
break; // allow trailing whitespace
}
match input.next() {
Ok(Token::Delim('+')) => {
products.push(try!(CalcLengthOrPercentage::parse_product(input, expected_unit)));
}
Ok(Token::Delim('-')) => {
let mut right = try!(CalcLengthOrPercentage::parse_product(input, expected_unit));
right.values.push(CalcValueNode::Number(-1.));
products.push(right);
}
_ => {
return Err(());
}
}
}
Ok(Token::Delim('-')) => {
let mut right = try!(CalcLengthOrPercentage::parse_product(input, expected_unit));
right.values.push(CalcValueNode::Number(-1.));
products.push(right);
}
_ => {
return Err(());
input.reset(position);
break
}
}
}
_ => {
input.reset(position);
break
}
}
}
}
Ok(CalcSumNode { products: products })
}

View file

@ -9,4 +9,7 @@ use style::values::specified::length::Length;
#[test]
fn test_calc() {
assert!(parse(Length::parse, "calc(1px+ 2px)").is_err());
assert!(parse(Length::parse, "calc( 1px + 2px )").is_ok());
assert!(parse(Length::parse, "calc(1px + 2px )").is_ok());
assert!(parse(Length::parse, "calc( 1px + 2px)").is_ok());
}