- From: Ms2ger <ms2ger@gmail.com>
- Date: Fri, 26 Aug 2011 14:22:46 +0200
- To: David Flanagan <dflanagan@mozilla.com>
- CC: www-dom@w3.org
On 08/25/2011 11:43 PM, David Flanagan wrote: > DOM Core ยง5.7 defines the setAttribute() method with an algorithm that > includes these final 2 steps: > >> >> 4. If the context object does not have an attribute whose local name >> is qualifiedName, create an attribute, whose local name is >> qualifiedName and value is value. Append this attribute to the context >> object's attributes. >> >> 5. Otherwise, set the value of the first attribute in the context >> object's attributes whose qualified name is qualifiedName, to value. > > Note that step 4 compares the first method argument to attribute's local > name, and step 5 compares the argument to the attribute's qualified > name. I think (and I hope) that step 4 is incorrect and should compare > against the qualified name like step 5 does. > > As written, I think the spec calls for the following unexpected behavior: > > // Create an element to test with > var e = document.createElement("div"); > // Define an attribute qname foo:bar, local name bar > e.setAttributeNS("foo", "foo:bar", "1"); > // Looks for attributes by qname, returns "1" > e.getAttribute("foo:bar") // "1" > // Here's where it gets weird. For this next line > // step 4 finds no attribute with localname "foo:bar" > // so it creates a new attribute with that as its local name. > // and as its qualified name. > e.setAttribute("foo:bar", "2"); > // When we repeat the query we still get "1" > // because getAttribute find the first attribute with the > // specified qname. > e.getAttribute("foo:bar") // "1" > // Now it gets weirder. We repeat the call to setAttribute() > // This time, the existance of the second attribute > // prevents the creation of a new one, but it is the first > // attribute that gets set: > e.setAttribute("foo:bar", "3"); > // The first foo:bar changed, so this time we get "3" > e.getAttribute("foo:bar") // "3" > > That can't be right, can it? No, I don't think so. Fixed: <http://dvcs.w3.org/hg/domcore/rev/cdc2e1b35166>. Thanks Ms2ger
Received on Friday, 26 August 2011 12:23:15 UTC