Bug 16680 - DOMTokenList assumes clean underlying string
DOMTokenList assumes clean underlying string
Status: RESOLVED WORKSFORME
Product: WebAppsWG
Classification: Unclassified
Component: DOM
unspecified
PC All
: P2 normal
: ---
Assigned To: Anne
public-webapps-bugzilla
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-04-10 10:46 UTC by Marcos Caceres
Modified: 2012-04-10 12:16 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.