Panic if DOMTokenList#contains is called for an unparsed attribute.

Previously, if the attribute was not parsed into a token list, and the
tokens() method returned None, DOMTokenList#contains would silently return
false. This issue was encountered in
<https://github.com/servo/servo/pull/4076> and took quite some time to
figure out.
This commit is contained in:
Ms2ger 2014-11-24 10:58:41 +01:00
parent 6e19955129
commit 449aaec5c2

View file

@ -90,10 +90,13 @@ impl<'a> DOMTokenListMethods for JSRef<'a, DOMTokenList> {
// http://dom.spec.whatwg.org/#dom-domtokenlist-contains
fn Contains(self, token: DOMString) -> Fallible<bool> {
self.check_token_exceptions(token.as_slice()).map(|slice| {
self.attribute().root().and_then(|attr| attr.value().tokens().map(|tokens| {
self.attribute().root().map(|attr| {
let value = attr.value();
let tokens = value.tokens()
.expect("Should have parsed this attribute");
let atom = Atom::from_slice(slice);
tokens.iter().any(|token| *token == atom)
})).unwrap_or(false)
}).unwrap_or(false)
})
}
}