From 0138bbcdd1e0cc9d544e0eff30057ff54cf3f04f Mon Sep 17 00:00:00 2001 From: radhika2896 Date: Tue, 7 Mar 2017 21:06:38 -0500 Subject: [PATCH 1/2] Require spaces around operators in calc() (fixes #15486) --- components/style/values/specified/length.rs | 34 +++++++++++++++------ tests/unit/style/parsing/length.rs | 12 ++++++++ tests/unit/style/parsing/mod.rs | 1 + 3 files changed, 37 insertions(+), 10 deletions(-) create mode 100644 tests/unit/style/parsing/length.rs diff --git a/components/style/values/specified/length.rs b/components/style/values/specified/length.rs index 97ef54845ab..2b75773a6ad 100644 --- a/components/style/values/specified/length.rs +++ b/components/style/values/specified/length.rs @@ -584,19 +584,33 @@ impl CalcLengthOrPercentage { let mut products = Vec::new(); products.push(try!(CalcLengthOrPercentage::parse_product(input, expected_unit))); - while let Ok(token) = input.next() { - match token { - Token::Delim('+') => { - 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))); } - Token::Delim('-') => { - let mut right = try!(CalcLengthOrPercentage::parse_product(input, expected_unit)); - right.values.push(CalcValueNode::Number(-1.)); - products.push(right); + + Ok(Token::Delim('-')) => { + let mut right = try!(CalcLengthOrPercentage::parse_product(input, expected_unit)); + right.values.push(CalcValueNode::Number(-1.)); + products.push(right); } - _ => return Err(()) + + _ => { + return Err(()); + } + } } - } + _ => { + input.reset(position); + break + } + } + } + Ok(CalcSumNode { products: products }) } diff --git a/tests/unit/style/parsing/length.rs b/tests/unit/style/parsing/length.rs new file mode 100644 index 00000000000..a76f26d826b --- /dev/null +++ b/tests/unit/style/parsing/length.rs @@ -0,0 +1,12 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +use parsing::parse; +use style::parser::Parse; +use style::values::specified::length::Length; + +#[test] +fn test_calc() { + assert!(parse(Length::parse, "calc(1px+ 2px)").is_err()); +} diff --git a/tests/unit/style/parsing/mod.rs b/tests/unit/style/parsing/mod.rs index cfaabc6c3c4..83cb6d1d1f7 100644 --- a/tests/unit/style/parsing/mod.rs +++ b/tests/unit/style/parsing/mod.rs @@ -87,6 +87,7 @@ mod font; mod image; mod inherited_box; mod inherited_text; +mod length; mod mask; mod outline; mod position; From 8666e82dbc37cac8de8d7cec16878cc8a91b9d78 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Wed, 8 Mar 2017 12:27:28 +0100 Subject: [PATCH 2/2] Silence a warning --- tests/unit/style/rule_tree/bench.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/style/rule_tree/bench.rs b/tests/unit/style/rule_tree/bench.rs index fccab1252f9..ba76d79b861 100644 --- a/tests/unit/style/rule_tree/bench.rs +++ b/tests/unit/style/rule_tree/bench.rs @@ -17,7 +17,7 @@ use test::{self, Bencher}; struct ErrorringErrorReporter; impl ParseErrorReporter for ErrorringErrorReporter { - fn report_error(&self, input: &mut Parser, position: SourcePosition, message: &str, + fn report_error(&self, _input: &mut Parser, position: SourcePosition, message: &str, url: &ServoUrl) { panic!("CSS error: {}\t\n{:?} {}", url.as_str(), position, message); }