Auto merge of #15611 - karan1276:karan_box_shadow, r=upsuper

In {box,text}-shadow so blur-radius does not accept negative values

 Change code for serialization for {box,text}-shadow so blur-radius can be parsed as non-negavite

---
<!-- 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 #15490 (github issue number if applicable).

<!-- Either: -->
- [x] Write tests

<!-- 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/15611)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-03-13 11:36:02 -07:00 committed by GitHub
commit 7db36abf67
2 changed files with 18 additions and 15 deletions

View file

@ -639,7 +639,6 @@ impl Shadow {
// disable_spread_and_inset is for filter: drop-shadow(...)
#[allow(missing_docs)]
pub fn parse(context: &ParserContext, input: &mut Parser, disable_spread_and_inset: bool) -> Result<Shadow, ()> {
let length_count = if disable_spread_and_inset { 3 } else { 4 };
let mut lengths = [Length::zero(), Length::zero(), Length::zero(), Length::zero()];
let mut lengths_parsed = false;
let mut color = None;
@ -655,21 +654,15 @@ impl Shadow {
if !lengths_parsed {
if let Ok(value) = input.try(|i| Length::parse(context, i)) {
lengths[0] = value;
let mut length_parsed_count = 1;
while length_parsed_count < length_count {
if let Ok(value) = input.try(|i| Length::parse(context, i)) {
lengths[length_parsed_count] = value
} else {
break
lengths[1] = try!(Length::parse(context, input));
if let Ok(value) = input.try(|i| Length::parse_non_negative(i)) {
lengths[2] = value;
if !disable_spread_and_inset {
if let Ok(value) = input.try(|i| Length::parse(context, i)) {
lengths[3] = value;
}
}
length_parsed_count += 1;
}
// The first two lengths must be specified.
if length_parsed_count < 2 {
return Err(())
}
lengths_parsed = true;
continue
}
@ -688,11 +681,12 @@ impl Shadow {
return Err(())
}
debug_assert!(!disable_spread_and_inset || lengths[3] == Length::zero());
Ok(Shadow {
offset_x: lengths[0].take(),
offset_y: lengths[1].take(),
blur_radius: lengths[2].take(),
spread_radius: if disable_spread_and_inset { Length::zero() } else { lengths[3].take() },
spread_radius: lengths[3].take(),
color: color,
inset: inset,
})

View file

@ -4,6 +4,7 @@
use cssparser::Parser;
use media_queries::CSSErrorReporterTest;
use parsing::parse;
use servo_url::ServoUrl;
use style::parser::ParserContext;
use style::properties::longhands::{self, perspective_origin, transform_origin};
@ -106,3 +107,11 @@ fn test_parse_factor() {
assert!(parse(filter::parse, "sepia(-1)").is_err());
assert!(parse(filter::parse, "saturate(-1)").is_err());
}
#[test]
fn blur_radius_should_not_accept_negavite_values() {
use style::properties::longhands::box_shadow;
assert!(parse(box_shadow::parse, "1px 1px -1px").is_err());// for -ve values
assert!(parse(box_shadow::parse, "1px 1px 0").is_ok());// for zero
assert!(parse(box_shadow::parse, "1px 1px 1px").is_ok());// for +ve value
}