Auto merge of #15869 - Iakis:NegBordRad, r=Wafflespeanut

Reject negative border radius

Replacerd Parse in parse_one_set_of_border_values with parse_non_negative and added tests for it
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [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).

<!-- Either: -->
- [X ] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- 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/15869)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-03-09 04:52:35 -08:00 committed by GitHub
commit e7efdfc655
2 changed files with 24 additions and 9 deletions

View file

@ -749,10 +749,10 @@ impl ToCss for BorderRadius {
} }
impl Parse for BorderRadius { impl Parse for BorderRadius {
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> { fn parse(_context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
let mut widths = try!(parse_one_set_of_border_values(context, input)); let mut widths = try!(parse_one_set_of_border_values(input));
let mut heights = if input.try(|input| input.expect_delim('/')).is_ok() { 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 { } else {
[widths[0].clone(), [widths[0].clone(),
widths[1].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], ()> { -> Result<[LengthOrPercentage; 4], ()> {
let a = try!(LengthOrPercentage::parse(context, input)); let a = try!(LengthOrPercentage::parse_non_negative(input));
let b = if let Ok(b) = input.try(|i| LengthOrPercentage::parse_non_negative(i)) {
let b = if let Ok(b) = input.try(|i| LengthOrPercentage::parse(context, i)) {
b b
} else { } else {
return Ok([a.clone(), a.clone(), a.clone(), a]) 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 c
} else { } else {
return Ok([a.clone(), b.clone(), a, b]) 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]) Ok([a, b, c, d])
} else { } else {
Ok([a, b.clone(), c, b]) Ok([a, b.clone(), c, b])

View file

@ -77,6 +77,22 @@ fn test_border_radius() {
assert_border_radius_values!("10px 20px 30px 40px / 1px 2px 3px 4px"; assert_border_radius_values!("10px 20px 30px 40px / 1px 2px 3px 4px";
"10px", "20px", "30px", "40px" ; "10px", "20px", "30px", "40px" ;
"1px", "2px", "3px", "4px"); "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] #[test]