Only allow border-image-outset to use non-negative values.

This commit is contained in:
J. Cliff Dyer 2016-11-23 09:19:56 -05:00
parent 72e4c6dc21
commit 46c4c9ce66
3 changed files with 34 additions and 6 deletions

View file

@ -242,7 +242,7 @@ ${helpers.single_keyword("-moz-float-edge", "content-box margin-box",
pub fn parse(_context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
let mut values = vec![];
for _ in 0..4 {
let value = input.try(|input| LengthOrNumber::parse(input));
let value = input.try(|input| LengthOrNumber::parse_non_negative(input));
match value {
Ok(val) => values.push(val),
Err(_) => break,

View file

@ -1009,3 +1009,13 @@ impl Parse for LengthOrPercentageOrAutoOrContent {
}
pub type LengthOrNumber = Either<Length, Number>;
impl LengthOrNumber {
pub fn parse_non_negative(input: &mut Parser) -> Result<Self, ()> {
if let Ok(v) = input.try(|i| Length::parse_non_negative(i)) {
Ok(Either::First(v))
} else {
Number::parse_non_negative(input).map(Either::Second)
}
}
}

View file

@ -12,7 +12,7 @@ use style::properties::shorthands::border_image;
use style::stylesheets::Origin;
#[test]
fn border_image_shorhand_should_parse_when_all_properties_specified() {
fn border_image_shorthand_should_parse_when_all_properties_specified() {
let url = ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let mut parser = Parser::new("linear-gradient(red, blue) 30 30% 45 fill / 20px 40px / 10px \
@ -28,7 +28,7 @@ fn border_image_shorhand_should_parse_when_all_properties_specified() {
}
#[test]
fn border_image_shorhand_should_parse_without_width() {
fn border_image_shorthand_should_parse_without_width() {
let url = ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let mut parser = Parser::new("linear-gradient(red, blue) 30 30% 45 fill / / 10px round stretch");
@ -43,7 +43,7 @@ fn border_image_shorhand_should_parse_without_width() {
}
#[test]
fn border_image_shorhand_should_parse_without_outset() {
fn border_image_shorthand_should_parse_without_outset() {
let url = ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let mut parser = Parser::new("linear-gradient(red, blue) 30 30% 45 fill / 20px 40px round");
@ -58,7 +58,7 @@ fn border_image_shorhand_should_parse_without_outset() {
}
#[test]
fn border_image_shorhand_should_parse_without_width_or_outset() {
fn border_image_shorthand_should_parse_without_width_or_outset() {
let url = ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let mut parser = Parser::new("linear-gradient(red, blue) 30 30% 45 fill round");
@ -73,7 +73,7 @@ fn border_image_shorhand_should_parse_without_width_or_outset() {
}
#[test]
fn border_image_shorhand_should_parse_with_just_source() {
fn border_image_shorthand_should_parse_with_just_source() {
let url = ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let mut parser = Parser::new("linear-gradient(red, blue)");
@ -86,3 +86,21 @@ fn border_image_shorhand_should_parse_with_just_source() {
assert_eq!(result.border_image_outset.unwrap(), border_image_outset::get_initial_specified_value());
assert_eq!(result.border_image_repeat.unwrap(), border_image_repeat::get_initial_specified_value());
}
#[test]
fn border_image_outset_should_error_on_negative_length() {
let url = ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let mut parser = Parser::new("-1em");
let result = border_image_outset::parse(&context, &mut parser);
assert_eq!(result, Err(()));
}
#[test]
fn border_image_outset_should_error_on_negative_number() {
let url = ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let mut parser = Parser::new("-15");
let result = border_image_outset::parse(&context, &mut parser);
assert_eq!(result, Err(()));
}