This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 16680 - DOMTokenList assumes clean underlying string
Summary: DOMTokenList assumes clean underlying string
Status: RESOLVED WORKSFORME
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: DOM (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal
Target Milestone: ---
Assignee: Anne
QA Contact: public-webapps-bugzilla
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-04-10 10:46 UTC by Marcos Caceres
Modified: 2012-04-10 12:16 UTC (History)
2 users (show)

See Also:


Attachments

Description Marcos Caceres 2012-04-10 10:46:10 UTC
The DOMTokenList assumes that the underlying string is always "clean" in that it contains no spaces at the start and at the end or in between. However, in the case of HTML's class attribute, the string can be "dirty", in that the underlying string is derived from a the class attribute. Consider:

element.className = "   class1  \n class2 \t     class3    \t \n"

In order to get a clean string, the spec needs to define something the following, so whitespace is removed:

//Splits the underlying string into a list of tokens
function splitUnderlyingString() {
  var underString = this.toString();
  var cleanString = underString.replace(/\s\s+/g, "\u0020").trim();
  return cleanString.split("\u0020");
}

Implementation already do the above, it seems. But the above is not clear in the spec.
Comment 2 Marcos Caceres 2012-04-10 12:16:12 UTC
(In reply to comment #1)
> The spec uses
> http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#split-a-string-on-spaces

Ah, my bad. Didn't notice the "split" link.