Skip to content

Commit

Permalink
style: Parse '0' as a number for border-image-width.
Browse files Browse the repository at this point in the history
As per CSS Values & Units:

"However, if a 0 could be parsed as either a <number> or a <length> in a
property (such as line-height), it must parse as a <number>."

(https://drafts.csswg.org/css-values-4/#lengths)

Differential Revision: https://phabricator.services.mozilla.com/D46723
  • Loading branch information
birtles authored and emilio committed Oct 9, 2019
1 parent a0e2aeb commit 877c6ac
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 20 deletions.
8 changes: 6 additions & 2 deletions components/style/values/generics/border.rs
Expand Up @@ -16,6 +16,7 @@ use style_traits::{CssWriter, ToCss};
Copy,
Debug,
MallocSizeOf,
Parse,
PartialEq,
SpecifiedValueInfo,
ToComputedValue,
Expand All @@ -25,10 +26,13 @@ use style_traits::{CssWriter, ToCss};
)]
#[repr(C, u8)]
pub enum GenericBorderImageSideWidth<LP, N> {
/// `<length-or-percentage>`
LengthPercentage(LP),
/// `<number>`
///
/// NOTE: Numbers need to be before length-percentagess, in order to parse
/// them first, since `0` should be a number, not the `0px` length.
Number(N),
/// `<length-or-percentage>`
LengthPercentage(LP),
/// `auto`
Auto,
}
Expand Down
18 changes: 0 additions & 18 deletions components/style/values/specified/border.rs
Expand Up @@ -180,24 +180,6 @@ impl BorderImageSideWidth {
}
}

impl Parse for BorderImageSideWidth {
fn parse<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
if input.try(|i| i.expect_ident_matching("auto")).is_ok() {
return Ok(GenericBorderImageSideWidth::Auto);
}

if let Ok(len) = input.try(|i| NonNegativeLengthPercentage::parse(context, i)) {
return Ok(GenericBorderImageSideWidth::LengthPercentage(len));
}

let num = NonNegativeNumber::parse(context, input)?;
Ok(GenericBorderImageSideWidth::Number(num))
}
}

impl Parse for BorderImageSlice {
fn parse<'i, 't>(
context: &ParserContext,
Expand Down

0 comments on commit 877c6ac

Please sign in to comment.