From f30537ba2b99cfaad94aff0d89f48c1180604753 Mon Sep 17 00:00:00 2001 From: karan sharma Date: Wed, 15 Feb 2017 16:24:45 +0530 Subject: [PATCH] Change code for serialization of {box,text}-shadow so blur-radius can be parsed as non-negavite --- components/style/values/specified/mod.rs | 24 +++++++++--------------- tests/unit/style/parsing/effects.rs | 9 +++++++++ 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/components/style/values/specified/mod.rs b/components/style/values/specified/mod.rs index 5c60141c689..60c169c55be 100644 --- a/components/style/values/specified/mod.rs +++ b/components/style/values/specified/mod.rs @@ -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 { - 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, }) diff --git a/tests/unit/style/parsing/effects.rs b/tests/unit/style/parsing/effects.rs index c1831de2c79..7453d423635 100644 --- a/tests/unit/style/parsing/effects.rs +++ b/tests/unit/style/parsing/effects.rs @@ -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 +}