servo: Merge #15454 - use `::parse_non_negative instead` of `::parse` for background_size property parsing (from jlevesy:bg-size-reject-negative-values); r=SimonSapin
authorJulien Levesy <jlevesy@gmail.com>
Thu, 09 Feb 2017 14:55:14 -0800
changeset 388372 76acb5c4721040b80e219577c7fed5b4d4ccad87
parent 388371 1e0dc444f8e3cd626b36e3ab16cfe416af427596
child 388373 67bbef7727963b44d9a070fc418f657ff779c193
push id7198
push userjlorenzo@mozilla.com
push dateTue, 18 Apr 2017 12:07:49 +0000
treeherdermozilla-beta@d57aa49c3948 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersSimonSapin
milestone54.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
servo: Merge #15454 - use `::parse_non_negative instead` of `::parse` for background_size property parsing (from jlevesy:bg-size-reject-negative-values); r=SimonSapin Use `::parse_non_negative` instead of `::parse` for background_size property parsing --- <!-- 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 #15450 <!-- Either: --> - [x] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: ce7827eadfcceb37e779846926c2b2f72c08dd72
servo/components/style/properties/longhand/background.mako.rs
servo/tests/unit/style/properties/background.rs
servo/tests/unit/style/properties/mod.rs
--- a/servo/components/style/properties/longhand/background.mako.rs
+++ b/servo/components/style/properties/longhand/background.mako.rs
@@ -368,45 +368,45 @@
     #[inline]
     pub fn get_initial_specified_value() -> SpecifiedValue {
         SpecifiedValue::Explicit(ExplicitSize {
             width: specified::LengthOrPercentageOrAuto::Auto,
             height: specified::LengthOrPercentageOrAuto::Auto,
         })
     }
 
-    pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue,()> {
+    pub fn parse(_context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue,()> {
         let width;
         if let Ok(value) = input.try(|input| {
             match input.next() {
                 Err(_) => Err(()),
                 Ok(Token::Ident(ref ident)) if ident.eq_ignore_ascii_case("cover") => {
                     Ok(SpecifiedValue::Cover)
                 }
                 Ok(Token::Ident(ref ident)) if ident.eq_ignore_ascii_case("contain") => {
                     Ok(SpecifiedValue::Contain)
                 }
                 Ok(_) => Err(()),
             }
         }) {
             return Ok(value)
         } else {
-            width = try!(specified::LengthOrPercentageOrAuto::parse(context, input))
+            width = try!(specified::LengthOrPercentageOrAuto::parse_non_negative(input))
         }
 
         let height;
         if let Ok(value) = input.try(|input| {
             match input.next() {
                 Err(_) => Ok(specified::LengthOrPercentageOrAuto::Auto),
                 Ok(_) => Err(()),
             }
         }) {
             height = value
         } else {
-            height = try!(specified::LengthOrPercentageOrAuto::parse(context, input));
+            height = try!(specified::LengthOrPercentageOrAuto::parse_non_negative(input));
         }
 
         Ok(SpecifiedValue::Explicit(ExplicitSize {
             width: width,
             height: height,
         }))
     }
 </%helpers:vector_longhand>
new file mode 100644
--- /dev/null
+++ b/servo/tests/unit/style/properties/background.rs
@@ -0,0 +1,19 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+use cssparser::Parser;
+use media_queries::CSSErrorReporterTest;
+use style::parser::ParserContext;
+use style::properties::longhands::background_size;
+use style::stylesheets::Origin;
+
+#[test]
+fn background_size_should_reject_negative_values() {
+    let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap();
+    let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
+
+    let parse_result = background_size::parse(&context, &mut Parser::new("-40% -40%"));
+
+    assert_eq!(parse_result.is_err(), true);
+}
--- a/servo/tests/unit/style/properties/mod.rs
+++ b/servo/tests/unit/style/properties/mod.rs
@@ -1,7 +1,8 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+mod background;
 mod scaffolding;
 mod serialization;
 mod viewport;