From b85f1a0240ffc6c3f98c2a37e21c6c063a12559b Mon Sep 17 00:00:00 2001 From: Carlos Martinez Date: Wed, 5 Apr 2017 18:37:34 +0200 Subject: [PATCH] Reject negative values of flex-basis. Fixes #15902 --- .../style/properties/longhand/position.mako.rs | 1 + components/style/values/specified/length.rs | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/components/style/properties/longhand/position.mako.rs b/components/style/properties/longhand/position.mako.rs index be5b1c2c9ed..c4a03e15deb 100644 --- a/components/style/properties/longhand/position.mako.rs +++ b/components/style/properties/longhand/position.mako.rs @@ -142,6 +142,7 @@ ${helpers.predefined_type("flex-basis", "LengthOrPercentageOrAutoOrContent", "computed::LengthOrPercentageOrAuto::Auto" if product == "gecko" else "computed::LengthOrPercentageOrAutoOrContent::Auto", + "parse_non_negative_with_context", spec="https://drafts.csswg.org/css-flexbox/#flex-basis-property", extra_prefixes="webkit", animatable=True if product == "gecko" else False)} diff --git a/components/style/values/specified/length.rs b/components/style/values/specified/length.rs index 1152c6f154c..ed31cc572e8 100644 --- a/components/style/values/specified/length.rs +++ b/components/style/values/specified/length.rs @@ -1170,6 +1170,14 @@ impl LengthOrPercentageOrAuto { pub fn parse_non_negative(input: &mut Parser) -> Result { LengthOrPercentageOrAuto::parse_internal(input, AllowedNumericType::NonNegative) } + + /// Parse a non-negative length, percentage, or auto. + #[inline] + pub fn parse_non_negative_with_context(_context: &ParserContext, + input: &mut Parser) + -> Result { + LengthOrPercentageOrAuto::parse_non_negative(input) + } } impl Parse for LengthOrPercentageOrAuto { @@ -1273,6 +1281,16 @@ pub enum LengthOrPercentageOrAutoOrContent { Content } +impl LengthOrPercentageOrAutoOrContent { + /// Alias to `parse` so that Gecko and Servo can use the same method name for + /// both `LengthOrPercentageOrAuto` and `LengthOrPercentageOrAutoOrContent`. + /// + /// NOTE: `parse` already only accepts non-negative values. + pub fn parse_non_negative_with_context(context: &ParserContext, input: &mut Parser) -> Result { + Self::parse(context, input) + } +} + impl HasViewportPercentage for LengthOrPercentageOrAutoOrContent { fn has_viewport_percentage(&self) -> bool { match *self {