Treat empty animation entry invalid draft
authorXidorn Quan <me@upsuper.org>
Mon, 06 Mar 2017 12:04:52 +1100
changeset 494025 ac337feefe3ec559e5b26c1441e6460e3fcc2a16
parent 494024 9690e07ed7462f5a0c4656dd8492682947340e35
child 494026 a6184eb5f60dc674d468f9f3f184a2f7eb320b73
push id47899
push userxquan@mozilla.com
push dateMon, 06 Mar 2017 10:53:41 +0000
milestone54.0a1
Treat empty animation entry invalid MozReview-Commit-ID: 6JX641zPaiK
servo/components/style/properties/shorthand/box.mako.rs
--- a/servo/components/style/properties/shorthand/box.mako.rs
+++ b/servo/components/style/properties/shorthand/box.mako.rs
@@ -169,40 +169,48 @@ macro_rules! try_parse_one {
             % endfor
         }
 
         fn parse_one_animation(context: &ParserContext, input: &mut Parser) -> Result<SingleAnimation,()> {
             % for prop in props:
             let mut ${prop} = None;
             % endfor
 
+            let mut parsed = 0;
             // NB: Name must be the last one here so that keywords valid for other
             // longhands are not interpreted as names.
             //
             // Also, duration must be before delay, see
             // https://drafts.csswg.org/css-animations/#typedef-single-animation
             loop {
+                parsed += 1;
                 try_parse_one!(context, input, duration, animation_duration);
                 try_parse_one!(context, input, timing_function, animation_timing_function);
                 try_parse_one!(context, input, delay, animation_delay);
                 try_parse_one!(context, input, iteration_count, animation_iteration_count);
                 try_parse_one!(input, direction, animation_direction);
                 try_parse_one!(input, fill_mode, animation_fill_mode);
                 try_parse_one!(input, play_state, animation_play_state);
                 try_parse_one!(context, input, name, animation_name);
 
+                parsed -= 1;
                 break
             }
 
-            Ok(SingleAnimation {
-                % for prop in props:
-                animation_${prop}: ${prop}.unwrap_or_else(animation_${prop}::single_value
-                                                          ::get_initial_specified_value),
-                % endfor
-            })
+            // If nothing is parsed, this is an invalid entry.
+            if parsed == 0 {
+                Err(())
+            } else {
+                Ok(SingleAnimation {
+                    % for prop in props:
+                    animation_${prop}: ${prop}.unwrap_or_else(animation_${prop}::single_value
+                                                              ::get_initial_specified_value),
+                    % endfor
+                })
+            }
         }
 
         % for prop in props:
         let mut ${prop}s = vec![];
         % endfor
 
         let results = try!(input.parse_comma_separated(|i| parse_one_animation(context, i)));
         for result in results.into_iter() {