servo: Merge #15514 - fix #15492 (Negative ShapeRadius values should be invalid) (from alon:master); r=emilio
authorAlon Levy <alon@pobox.com>
Sun, 12 Feb 2017 03:15:36 -0800
changeset 372194 2b147f3dcae89e547ce05bae480389eed1aa45f6
parent 372193 30cd8908e5ffb8fb980bf1485cef330484c0453c
child 372195 d2b73aaa759a7d22aabc6d16fa257a7d1ac9638e
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemilio
milestone54.0a1
servo: Merge #15514 - fix #15492 (Negative ShapeRadius values should be invalid) (from alon:master); r=emilio <!-- Please describe your changes on the following line: --> Address issue #15492 - Negative value in <shape-radius> should be invalid --- - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #15492 (github issue number if applicable). - [X] There are tests for these changes <!-- 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: 45db39cc0406a90273a5a74738fe94943a57b142
servo/components/style/values/specified/basic_shape.rs
servo/tests/unit/style/parsing/basic_shape.rs
--- a/servo/components/style/values/specified/basic_shape.rs
+++ b/servo/components/style/values/specified/basic_shape.rs
@@ -657,18 +657,18 @@ impl ShapeRadius {
 
 impl Default for ShapeRadius {
     fn default() -> Self {
         ShapeRadius::ClosestSide
     }
 }
 
 impl Parse for ShapeRadius {
-    fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
-        input.try(|i| LengthOrPercentage::parse(context, i)).map(ShapeRadius::Length).or_else(|_| {
+    fn parse(_: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
+        input.try(|i| LengthOrPercentage::parse_non_negative(i)).map(ShapeRadius::Length).or_else(|_| {
             match_ignore_ascii_case! { try!(input.expect_ident()),
                 "closest-side" => Ok(ShapeRadius::ClosestSide),
                 "farthest-side" => Ok(ShapeRadius::FarthestSide),
                 _ => Err(())
             }
         })
     }
 }
--- a/servo/tests/unit/style/parsing/basic_shape.rs
+++ b/servo/tests/unit/style/parsing/basic_shape.rs
@@ -91,16 +91,18 @@ fn test_circle() {
     assert_roundtrip_basicshape!(Circle::parse, "circle(at top center)", "circle(at 50% 0%)");
     assert_roundtrip_basicshape!(Circle::parse, "circle(at center top)", "circle(at 50% 0%)");
     assert_roundtrip_basicshape!(Circle::parse, "circle(at 40% top)", "circle(at 40% 0%)");
     assert_roundtrip_basicshape!(Circle::parse, "circle(at 10px 100px)", "circle(at 10px 100px)");
     // closest-side is omitted, because it is the default
     assert_roundtrip_basicshape!(Circle::parse, "circle(closest-side at center)", "circle(at 50% 50%)");
     assert_roundtrip_basicshape!(Circle::parse, "circle(farthest-side at center)",
                                                 "circle(farthest-side at 50% 50%)");
+    assert_roundtrip_basicshape!(Circle::parse, "circle(10px)",
+                                                "circle(10px at 50% 50%)");
     assert_roundtrip_basicshape!(Circle::parse, "circle(20px at center)", "circle(20px at 50% 50%)");
     assert_roundtrip_basicshape!(Circle::parse, "circle(calc(1px + 50%) at center)",
                                                 "circle(calc(1px + 50%) at 50% 50%)");
 
     assert_roundtrip_basicshape!(Circle::parse, "circle(at right 5px bottom 10px)",
                                                 "circle(at right 5px bottom 10px)");
     assert_roundtrip_basicshape!(Circle::parse, "circle(at bottom 5px right 10px)",
                                                 "circle(at right 10px bottom 5px)");
@@ -109,16 +111,17 @@ fn test_circle() {
     assert_roundtrip_basicshape!(Circle::parse, "circle(at right 5% bottom 0px)",
                                                 "circle(at 95% 100%)");
     assert_roundtrip_basicshape!(Circle::parse, "circle(at right 5% bottom 1px)",
                                                 "circle(at right 5% bottom 1px)");
     assert_roundtrip_basicshape!(Circle::parse, "circle(at 5% bottom 1px)",
                                                 "circle(at left 5% bottom 1px)");
 
     assert!(parse(Circle::parse, "circle(at top 40%)").is_err());
+    assert!(parse(Circle::parse, "circle(-10px)").is_err());
 }
 
 #[test]
 fn test_ellipse() {
     assert_roundtrip_basicshape!(Ellipse::parse, "ellipse(at center)", "ellipse(at 50% 50%)");
     assert_roundtrip_basicshape!(Ellipse::parse, "ellipse()", "ellipse(at 50% 50%)");
     assert_roundtrip_basicshape!(Ellipse::parse, "ellipse(at left bottom)", "ellipse(at 0% 100%)");
     assert_roundtrip_basicshape!(Ellipse::parse, "ellipse(at bottom left)", "ellipse(at 0% 100%)");