servo: Merge #18644 - stylo: Don't error out on trailing whitespace in attr() (from Manishearth:stylo-attr-ws); r=bz

r=bz bug 1403282

Source-Repo: https://github.com/servo/servo
Source-Revision: 97227aaca3613e22afc832554d29f7f7fdfb7220

--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : d922f5a3b76b92c444cd12c9b279ee1c09481385
This commit is contained in:
Manish Goregaokar 2017-09-26 23:56:15 -05:00
Родитель 5e148c52b0
Коммит b4eac691a8
1 изменённых файлов: 24 добавлений и 20 удалений

Просмотреть файл

@ -740,28 +740,32 @@ impl Attr {
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 {