<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>22958</bug_id>
          
          <creation_ts>2008-12-22 01:10:55 -0800</creation_ts>
          <short_desc>Attribute namespaces are serialized as if they were element ones</short_desc>
          <delta_ts>2019-02-06 09:03:45 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>DOM</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Alexey Proskuryakov">ap</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>alex</cc>
    
    <cc>cdumez</cc>
    
    <cc>emacemac7</cc>
    
    <cc>jchaffraix</cc>
    
    <cc>peter.rietzler</cc>
    
    <cc>rwlbuis</cc>
    
    <cc>webkitbooger</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>103161</commentid>
    <comment_count>0</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2008-12-22 01:10:55 -0800</bug_when>
    <thetext>If an attribute is created with setAttributeNS(), its namespace is printed as if it were a default one.

On the attached test, two default namespaces are printed.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>103162</commentid>
    <comment_count>1</comment_count>
      <attachid>26197</attachid>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2008-12-22 01:11:17 -0800</bug_when>
    <thetext>Created attachment 26197
test case</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>383287</commentid>
    <comment_count>2</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2011-04-11 11:12:17 -0700</bug_when>
    <thetext>*** Bug 58221 has been marked as a duplicate of this bug. ***</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>869065</commentid>
    <comment_count>3</comment_count>
    <who name="Leo B">webkitbooger</who>
    <bug_when>2013-04-04 02:09:35 -0700</bug_when>
    <thetext>Still seeing essentially same problem in Google Chrome Version 26.0.1410.43 m.

As verified in the developer tools debugger, in scope variables, setAttributeNS does this:

For the element creates an attribute, but the attribute&apos;s namespaceURI is null.

And for the element it creates a second attribute that hasn&apos;t been asked for, of name xmlns with value being what should have been the namespaceURI of the attribute that has been asked for.

The solution / workaround is:  Pass in a qualified name and it will work!  For most compatibility, you probably should get the prefix with yourElement.lookupPrefix(yourNamespaceURI).

Workaround found by paying attention to http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-ElSetAttrNS where it says the second parameter is the qualifiedName, the qualified name of the attribute to create or alter.

Problem found when running new tests in http://srguiwiz.github.com/adj-js/user-docs/tests.html and it failed in Chrome as a consequence of setAttributeNS behavior.  It had passed in Firefox.  Since then fixed http://srguiwiz.github.com/adj-js/user-docs/ to use qualified name, now it works in Chrome as well.

Does this workaround and the specification mean this isn&apos;t a bug any more?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>900810</commentid>
    <comment_count>4</comment_count>
    <who name="Alex Milowski">alex</who>
    <bug_when>2013-06-15 14:48:06 -0700</bug_when>
    <thetext>(In reply to comment #3)

&gt; 
&gt; Does this workaround and the specification mean this isn&apos;t a bug any more?

This is still a bug.  The DOM API allows for the case where the prefix is not specified.  In such cases, the serializer needs to generate a prefix.

In my testing, the serializer clearly assumes the prefix property will be present.  The extra default namespace comes from the attempt to declare the prefix used for the namespace attribute.  When the prefix is not specified and there needs to be a prefix, the wrong thing happens.

I have a simple example the demonstrates the problem that I will attach.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>900811</commentid>
    <comment_count>5</comment_count>
      <attachid>204774</attachid>
    <who name="Alex Milowski">alex</who>
    <bug_when>2013-06-15 14:51:46 -0700</bug_when>
    <thetext>Created attachment 204774
A example that demonstrates the different possible ways to cause and/or fix the problem.

Note: In Firefox, you aren&apos;t allowed to set the prefix.  This is clearly a DOM bug for them as [1] says you are allowed to set the prefix. 

[1] http://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-NodeNSPrefix</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>901576</commentid>
    <comment_count>6</comment_count>
    <who name="Alex Milowski">alex</who>
    <bug_when>2013-06-18 16:22:54 -0700</bug_when>
    <thetext>Looking at the source, the problem is two fold:

  1. A prefix is not generated for the qualified name when it is missing.

  2. The attribute prefix, when set, is not passed properly to appendNamespace().


For (1), at MarkupAccumulator.cpp:455:
 
       QualifiedName prefixedName = attribute.name();
        if (attribute.namespaceURI() == XLinkNames::xlinkNamespaceURI) {
            if (!attribute.prefix())
                prefixedName.setPrefix(xlinkAtom);
        } else if (attribute.namespaceURI() == XMLNames::xmlNamespaceURI) {
            if (!attribute.prefix())
                prefixedName.setPrefix(xmlAtom);
        } else if (attribute.namespaceURI() == XMLNSNames::xmlnsNamespaceURI) {
            if (attribute.name() != XMLNSNames::xmlnsAttr &amp;&amp; !attribute.prefix())
                prefixedName.setPrefix(xmlnsAtom);
        }
        result.append(prefixedName.toString());

There are an infinite number of cases that need to be handled here by a check for:

   } else if (attribute.namespaceURI() &amp;&amp; !attribute.prefix()) {
       // generate a prefix ...
   }

and that is missing.

For (2), the actually prefix used (either what was set or what was given) needs to be tracked and passed later on to appendNamespace() instead of attribute.prefix() as that field may remain null in the case of generated or set prefixes.

Because you have to generate namespaces, it is unclear to me as of yet whether the current method of tracking in-scope namespaces will work properly.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>901591</commentid>
    <comment_count>7</comment_count>
    <who name="Alex Milowski">alex</who>
    <bug_when>2013-06-18 17:11:12 -0700</bug_when>
    <thetext>Bug 117764 is related to this problem.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>922435</commentid>
    <comment_count>8</comment_count>
    <who name="Rob Buis">rwlbuis</who>
    <bug_when>2013-08-29 06:46:49 -0700</bug_when>
    <thetext>Committed r154779: &lt;http://trac.webkit.org/changeset/154779&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1503032</commentid>
    <comment_count>9</comment_count>
    <who name="Lucas Forschler">lforschler</who>
    <bug_when>2019-02-06 09:03:45 -0800</bug_when>
    <thetext>Mass moving XML DOM bugs to the &quot;DOM&quot; Component.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>26197</attachid>
            <date>2008-12-22 01:11:17 -0800</date>
            <delta_ts>2008-12-22 01:11:17 -0800</delta_ts>
            <desc>test case</desc>
            <filename>setAttributeNS.xml</filename>
            <type>application/xhtml+xml</type>
            <size>493</size>
            <attacher name="Alexey Proskuryakov">ap</attacher>
            
              <data encoding="base64">PGh0bWwgeG1sOmxhbmc9ImVuIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94aHRtbCI+
CiA8aGVhZD4KICA8dGl0bGUvPgogIDxzY3JpcHQgdHlwZT0idGV4dC9qYXZhc2NyaXB0Ij4KICAg
IGZ1bmN0aW9uIGRvVGVzdDEoKSB7CiAgICAgIGRvY3VtZW50LmdldEVsZW1lbnRCeUlkKCdyZXN1
bHQxJykuc2V0QXR0cmlidXRlTlMoJ25zJywgJ3RpdGxlJywgJ3ZhbHVlJyk7CiAgICAgIGlmIChk
b2N1bWVudC5nZXRFbGVtZW50QnlJZCgncmVzdWx0MScpLm91dGVySFRNTC5tYXRjaCgneG1sbnM9
Im5zIicpKQogICAgICAgIGFsZXJ0KCdGQUlMOiAnICsgZG9jdW1lbnQuZ2V0RWxlbWVudEJ5SWQo
J3Jlc3VsdDEnKS5vdXRlckhUTUwpOwogICAgICBlbHNlCiAgICAgICAgYWxlcnQoIlBBU1MiKTsK
ICAgIH0KICA8L3NjcmlwdD4KIDwvaGVhZD4KIDxib2R5IG9ubG9hZD0iZG9UZXN0MSgpIj4KICA8
cCBpZD0icmVzdWx0MSI+PC9wPgogPC9ib2R5Pgo8L2h0bWw+Cg==
</data>

          </attachment>
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>204774</attachid>
            <date>2013-06-15 14:51:46 -0700</date>
            <delta_ts>2013-06-15 14:51:46 -0700</delta_ts>
            <desc>A example that demonstrates the different possible ways to cause and/or fix the problem.</desc>
            <filename>xml-serialization.xhtml</filename>
            <type>application/xhtml+xml</type>
            <size>2984</size>
            <attacher name="Alex Milowski">alex</attacher>
            
              <data encoding="base64">PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPCFET0NUWVBFIGh0bWw+Cjxo
dG1sIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hodG1sIj4KICAgIDxoZWFkPgogICAg
ICAgIDx0aXRsZT5YTUwgU2VyaWFsaXphdGlvbiBUZXN0PC90aXRsZT4KICAgICAgICA8c2NyaXB0
IHR5cGU9InRleHQvamF2YXNjcmlwdCI+CiAgIHZhciBzZXJpYWxpemVyID0gbmV3IFhNTFNlcmlh
bGl6ZXIoKTsKCiAgIC8vIEV4YW1wbGUgMTogQ3JlYXRlIGEgZG9jdW1lbnQgd2l0aCBhIG5hbWVz
cGFjZWQgYXR0cmlidXRlIGJ1dCB2aWEgdGhlIERPTSBBUEkgYnV0IGRvIG5vdCBzcGVjaWZpYyBh
IHByZWZpeC4KICAgLy8gT3V0Y29tZTogIEZhaWxlZCB0byBzZXJpYWxpemUgY29ycmVjdGx5Lgog
ICB2YXIgZG9jID0gZG9jdW1lbnQuaW1wbGVtZW50YXRpb24uY3JlYXRlRG9jdW1lb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