Bug 1403282 - stylo: Don't error out on trailing whitespace in attr(); r?bz draft
authorManish Goregaokar <manishearth@gmail.com>
Tue, 26 Sep 2017 13:40:22 -0700
changeset 670796 af9d86b9edf1d51654d2a81ba4bf4fddbb9d0115
parent 669596 7e962631ba4298bcefa571008661983d77c3e652
child 670797 0a282c5b00f4aeb993e8f19ab092e50cae7c9bf4
push id81711
push userbmo:manishearth@gmail.com
push dateTue, 26 Sep 2017 20:55:23 +0000
reviewersbz
bugs1403282
milestone58.0a1
Bug 1403282 - stylo: Don't error out on trailing whitespace in attr(); r?bz MozReview-Commit-ID: D9EWGgeiI4D
servo/components/style/values/specified/mod.rs
--- a/servo/components/style/values/specified/mod.rs
+++ b/servo/components/style/values/specified/mod.rs
@@ -735,38 +735,42 @@ impl Attr {
     /// within a parse_nested_block()
     pub fn parse_function<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
                                   -> Result<Attr, ParseError<'i>> {
         // Syntax is `[namespace? `|`]? ident`
         // no spaces allowed
         let first = input.try(|i| i.expect_ident_cloned()).ok();
         if let Ok(token) = input.try(|i| i.next_including_whitespace().map(|t| t.clone())) {
             match token {
-                Token::Delim('|') => {}
+                Token::Delim('|') => {
+                    // must be followed by an ident
+                    let second_token = match *input.next_including_whitespace()? {
+                        Token::Ident(ref second) => second,
+                        ref t => return Err(BasicParseError::UnexpectedToken(t.clone()).into()),
+                    };
+
+                    let ns_with_id = if let Some(ns) = first {
+                        let ns = Namespace::from(ns.as_ref());
+                        let id: Result<_, ParseError> =
+                            get_id_for_namespace(&ns, context)
+                            .map_err(|()| StyleParseError::UnspecifiedError.into());
+                        Some((ns, id?))
+                    } else {
+                        None
+                    };
+                    return Ok(Attr {
+                        namespace: ns_with_id,
+                        attribute: second_token.as_ref().to_owned(),
+                    })
+                }
+                // In the case of attr(foobar    ) we don't want to error out
+                // because of the trailing whitespace
+                Token::WhiteSpace(_) => (),
                 ref t => return Err(BasicParseError::UnexpectedToken(t.clone()).into()),
             }
-            // must be followed by an ident
-            let second_token = match *input.next_including_whitespace()? {
-                Token::Ident(ref second) => second,
-                ref t => return Err(BasicParseError::UnexpectedToken(t.clone()).into()),
-            };
-
-            let ns_with_id = if let Some(ns) = first {
-                let ns = Namespace::from(ns.as_ref());
-                let id: Result<_, ParseError> =
-                    get_id_for_namespace(&ns, context)
-                    .map_err(|()| StyleParseError::UnspecifiedError.into());
-                Some((ns, id?))
-            } else {
-                None
-            };
-            return Ok(Attr {
-                namespace: ns_with_id,
-                attribute: second_token.as_ref().to_owned(),
-            })
         }
 
         if let Some(first) = first {
             Ok(Attr {
                 namespace: None,
                 attribute: first.as_ref().to_owned(),
             })
         } else {