From c04622260ad01afac1c72241835d25baaab6e51f Mon Sep 17 00:00:00 2001 From: # <#> Date: Thu, 9 Mar 2017 04:52:35 -0800 Subject: [PATCH] servo: Merge #15869 - Reject negative border radius (from Iakis:NegBordRad); r=Wafflespeanut Replacerd Parse in parse_one_set_of_border_values with parse_non_negative and added tests for it --- - [X ] `./mach build -d` does not report any errors - [ X] `./mach test-tidy` does not report any errors - [X ] These changes fix #15345 (github issue number if applicable). - [X ] There are tests for these changes OR - [ ] These changes do not require tests because _____ Source-Repo: https://github.com/servo/servo Source-Revision: e7efdfc6551433feb037dfeb3cbbd1f0c22b8ea1 --HG-- extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear extra : subtree_revision : 51d49c908ed01c3f87ac17529b309d3d20b2f6fb --- .../style/values/specified/basic_shape.rs | 17 ++++++++--------- servo/tests/unit/style/parsing/basic_shape.rs | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/servo/components/style/values/specified/basic_shape.rs b/servo/components/style/values/specified/basic_shape.rs index 8c1adef9ee1b..45815eb7cc78 100644 --- a/servo/components/style/values/specified/basic_shape.rs +++ b/servo/components/style/values/specified/basic_shape.rs @@ -749,10 +749,10 @@ impl ToCss for BorderRadius { } impl Parse for BorderRadius { - fn parse(context: &ParserContext, input: &mut Parser) -> Result { - let mut widths = try!(parse_one_set_of_border_values(context, input)); + fn parse(_context: &ParserContext, input: &mut Parser) -> Result { + let mut widths = try!(parse_one_set_of_border_values(input)); let mut heights = if input.try(|input| input.expect_delim('/')).is_ok() { - try!(parse_one_set_of_border_values(context, input)) + try!(parse_one_set_of_border_values(input)) } else { [widths[0].clone(), widths[1].clone(), @@ -768,23 +768,22 @@ impl Parse for BorderRadius { } } -fn parse_one_set_of_border_values(context: &ParserContext, mut input: &mut Parser) +fn parse_one_set_of_border_values(mut input: &mut Parser) -> Result<[LengthOrPercentage; 4], ()> { - let a = try!(LengthOrPercentage::parse(context, input)); - - let b = if let Ok(b) = input.try(|i| LengthOrPercentage::parse(context, i)) { + let a = try!(LengthOrPercentage::parse_non_negative(input)); + let b = if let Ok(b) = input.try(|i| LengthOrPercentage::parse_non_negative(i)) { b } else { return Ok([a.clone(), a.clone(), a.clone(), a]) }; - let c = if let Ok(c) = input.try(|i| LengthOrPercentage::parse(context, i)) { + let c = if let Ok(c) = input.try(|i| LengthOrPercentage::parse_non_negative(i)) { c } else { return Ok([a.clone(), b.clone(), a, b]) }; - if let Ok(d) = input.try(|i| LengthOrPercentage::parse(context, i)) { + if let Ok(d) = input.try(|i| LengthOrPercentage::parse_non_negative(i)) { Ok([a, b, c, d]) } else { Ok([a, b.clone(), c, b]) diff --git a/servo/tests/unit/style/parsing/basic_shape.rs b/servo/tests/unit/style/parsing/basic_shape.rs index 9fb65563be46..dcb269c93977 100644 --- a/servo/tests/unit/style/parsing/basic_shape.rs +++ b/servo/tests/unit/style/parsing/basic_shape.rs @@ -77,6 +77,22 @@ fn test_border_radius() { assert_border_radius_values!("10px 20px 30px 40px / 1px 2px 3px 4px"; "10px", "20px", "30px", "40px" ; "1px", "2px", "3px", "4px"); + assert_border_radius_values!("10px 20px 30px 40px / 1px 2px 3px 4px"; + "10px", "20px", "30px", "40px" ; + "1px", "2px", "3px", "4px"); + assert_border_radius_values!("10px 20px 30px 40px / 1px 2px 3px 4px"; + "10px", "20px", "30px", "40px" ; + "1px", "2px", "3px", "4px"); + assert_border_radius_values!("10px -20px 30px 40px"; + "10px", "10px", "10px", "10px"; + "10px", "10px", "10px", "10px"); + assert_border_radius_values!("10px 20px -30px 40px"; + "10px", "20px", "10px", "20px"; + "10px", "20px", "10px", "20px"); + assert_border_radius_values!("10px 20px 30px -40px"; + "10px", "20px", "30px", "20px"; + "10px", "20px", "30px", "20px"); + assert!(parse(BorderRadius::parse, "-10px 20px 30px 40px").is_err()); } #[test]