From c5f7e553e43d865194d3251e584b166f4aa1095d Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Tue, 16 Dec 2014 11:02:04 -0400 Subject: [PATCH] Avoid duplicated tokens in AttrValue::from_serialized_tokenlist --- components/script/dom/attr.rs | 8 ++++++-- tests/wpt/metadata/dom/nodes/Element-classlist.html.ini | 6 ------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/components/script/dom/attr.rs b/components/script/dom/attr.rs index 2b821371819..a848ca85e0c 100644 --- a/components/script/dom/attr.rs +++ b/components/script/dom/attr.rs @@ -38,8 +38,12 @@ pub enum AttrValue { impl AttrValue { pub fn from_serialized_tokenlist(tokens: DOMString) -> AttrValue { - let atoms = split_html_space_chars(tokens.as_slice()) - .map(|token| Atom::from_slice(token)).collect(); + let mut atoms: Vec = vec!(); + for token in split_html_space_chars(tokens.as_slice()).map(|slice| Atom::from_slice(slice)) { + if !atoms.iter().any(|atom| *atom == token) { + atoms.push(token); + } + } AttrValue::TokenList(tokens, atoms) } diff --git a/tests/wpt/metadata/dom/nodes/Element-classlist.html.ini b/tests/wpt/metadata/dom/nodes/Element-classlist.html.ini index c072735d502..3ec7b9070e1 100644 --- a/tests/wpt/metadata/dom/nodes/Element-classlist.html.ini +++ b/tests/wpt/metadata/dom/nodes/Element-classlist.html.ini @@ -3,9 +3,6 @@ [CSS .foo selectors must not match elements without any class] expected: FAIL - [classList must be correct for an element that has classes] - expected: FAIL - [empty classList should return the empty string since the ordered set parser skip the whitespaces] expected: FAIL @@ -63,9 +60,6 @@ [classList.remove must not break case-sensitive CSS selector matching] expected: FAIL - [classList.remove must remove duplicated tokens] - expected: FAIL - [classList.remove must collapse whitespace around removed tokens] expected: FAIL