W3C home > Mailing lists > Public > public-html@w3.org > May 2008

Re: Whitespace in attribute values

From: Thomas Broyer <t.broyer@gmail.com>
Date: Sat, 24 May 2008 19:45:06 +0200
Message-ID: <a9699fd20805241045j2b5d306euaba4ded665b7f4e5@mail.gmail.com>
To: public-html@w3.org

On Sat, May 24, 2008 at 6:24 PM, Andrew Sidwell <w3c@andrewsidwell.co.uk> wrote:
> http://software.hixie.ch/utilities/js/live-dom-viewer/?%3C!DOCTYPE%20html%3E%0A%3Ca%20href%3D%22%20%20%20http%3A%2F%2Fgoogle.com%2Fsearch%3Fq%3Dhello%20%20world%20%20%20%20%20%22%20class%3D%22%20%20%20raga%20taga%20%20%20%20%22%20new%3D%22%20%20%20raga%20%20haga%20%20%22%3Emeow%3C%2Fa%3E%0A
> <!DOCTYPE html>
> <a href="   http://google.com/search?q=hello  world     "
>   class="   raga taga    " new="   raga  haga  ">meow</a>
> I can't find anywhere in the spec which defines how to deal with whitespace
> in attribute values.  Special handling seems to be in browsers for the
> "href" and "class" attributes, and more general handling in others.

That's a bug in the Live DOM viewer (change the href attribute value
to a relative URI reference to exhibit the bug: the DOM view shows the
resolved URI).

See for comparison (look at the "log" section):

<!DOCTYPE html>
<a href="   search?q=hello  world     " class="   raga taga    " new="
  raga  haga  ">meow</a>
w("href:  [" + document.getElementsByTagName('a')[0].getAttribute('href',
2) + "]");
w("class: [" + (document.getElementsByTagName('a')[0].getAttribute('class',
2) || document.getElementsByTagName('a')[0].getAttribute('className',
2)) + "]");
w("new:   [" + document.getElementsByTagName('a')[0].getAttribute('new',
2) + "]");

> Opera and Safari3 trim any runs of whitespace in any attribute value into
> just one space character.  Ff3 does this but also then removes any leading
> or trailing spaces from the class attribute.

I don't have Opera at hand, but Safari 3 and Firefox 3 (RC1) don't
change the attribute values; except Firefox 3 on the @class attribute
(see the bug linked to by Boris).

> IE removes all leading or trailing whitespace from the href attribute's
> value, leaving other attribute values as written.

Note that the script is using getAttribute(..., 2) to get the actual
attribute value in IE:

I've also defaulted to className is class is not found, as IE does not
support getting attribute "class" (except in IE8, according to the doc
http://msdn.microsoft.com/en-us/library/cc304686(VS.85).aspx )

IE7 then does not change the attribute values.

Thomas Broyer
Received on Saturday, 24 May 2008 17:45:45 UTC

This archive was generated by hypermail 2.3.1 : Thursday, 29 October 2015 10:15:33 UTC