Bug 111307 - div.classList.add('a', 'a') creates duplicate entries
Summary: div.classList.add('a', 'a') creates duplicate entries
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Nobody
URL: http://jsfiddle.net/m_gol/xje3k/
Keywords:
Depends on:
Blocks:
 
Reported: 2013-03-04 05:56 PST by Michał Gołębiowski
Modified: 2015-08-28 11:20 PDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michał Gołębiowski 2013-03-04 05:56:32 PST
div.classList.add('a', 'a') should IMHO add only one instance of 'a' to div.classList.
Comment 1 Michał Gołębiowski 2013-03-04 13:20:48 PST
One result of this issue is that results of invoking:

div.classList.add(sth1, sth2);

and:

div.classList.add(sth1);
div.classList.add(sth2);

are different, which is unintuitive.
Comment 2 Michał Gołębiowski 2013-03-04 13:23:39 PST
(In reply to comment #1)
> One result of this issue is that results of invoking:
> 
> div.classList.add(sth1, sth2);
> 
> and:
> 
> div.classList.add(sth1);
> div.classList.add(sth2);
> 
> are different, which is unintuitive.

Correction: results CAN be different, not ARE different, of course.
Comment 3 Michał Gołębiowski 2013-03-05 00:18:29 PST
OK, this is not only my view, this is what spec dictates:
http://dom.spec.whatwg.org/#domtokenlist
"A DOMTokenList object has an associated list of unique tokens, which is initially empty."
So it's clearly WebKit's bug.
Comment 4 Michał Gołębiowski 2013-04-17 10:37:17 PDT
Chromium ticket: https://code.google.com/p/chromium/issues/detail?id=232448
Comment 5 Andrea Giammarchi 2013-10-08 18:42:41 PDT
confirmed and fixed/verified through the test 74 in here: http://webreflection.github.io/dom4/test/

The check is basically this one:

div.classList.add('a', 'b', 'a');
assert(div.className === 'a b');

the test against to verify it works is the one showed here:
div.classList.add('a', 'a');
assert(div.className === 'a');

Very weird this bus hasn't been confirmed yet since it's clearly stated about being unique tokens.

What would be the reason to have twice the same class otherwise, having an `!important` effect ?

Thanks for fixing this, I don't really want to rely on JS to fix such simple CSS classList core gotcha.

Best Regards
Comment 6 Michał Gołębiowski 2013-12-29 14:17:34 PST
The issue has been fixed in Chrome over two months ago, I also got some feedback in a sensible time after reporting. Meanwhile, here no one seems to bother.

Could sb at least triage this? Important, not important, some milestone? This lack of response is disheartening.
Comment 7 Michał Gołębiowski 2015-08-28 11:20:17 PDT
I wish someone looked at those bug reports. :(

Thankfully, this has been fixed in Safari 8.