From 449aaec5c2a9a5d1d1a55e6e5bdc35ccdbbc9577 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Mon, 24 Nov 2014 10:58:41 +0100 Subject: [PATCH] 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 and took quite some time to figure out. --- components/script/dom/domtokenlist.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/components/script/dom/domtokenlist.rs b/components/script/dom/domtokenlist.rs index a7326fa8e2d..d05606965b2 100644 --- a/components/script/dom/domtokenlist.rs +++ b/components/script/dom/domtokenlist.rs @@ -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 { 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) }) } }