Closed
      
        Bug 350442
      
      
        Opened 19 years ago
          Closed 19 years ago
      
        
    
  
toXMLString omits namespace definition 
    Categories
(Core :: JavaScript Engine, defect)
Tracking
()
        VERIFIED
        FIXED
        
    
  
People
(Reporter: lubos, Assigned: Waldo)
Details
(Keywords: verified1.8.1)
Attachments
(1 file)
| 
        
        
         2.89 KB,
          patch         
       | 
      
           brendan
 :
              
              review+
          beltzner
 :
              
              approval1.8.1+
           | 
      Details | Diff | Splinter Review | 
User-Agent:       Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)
Build Identifier: JavaScript-C 1.7 pre-release 1 2006-04-04
After adding an attribute to tag the atribute's namespace prefix is retained correctly but the namespace definition is lost; toXMLString thus produces invalid XML markup. The XML object itself seems to be OK.
Reproducible: Always
Steps to Reproduce:
1. Run example from additional information under jsshell.
Actual Results:  
<tag1 xmlns="http://ns1" ns2:a1="a1 from ns2"/>
Expected Results:  
<tag1 xmlns="http://ns1" xmlns:ns2="http://ns2" ns2:a1="a1 from ns2"/>
Example:
var t1 = <tag1 xmlns="http://ns1"/>
var n2 = new Namespace("http://ns2")
t1.@n2::a1="a1 from ns2"
print(t1.toXMLString())
          Comment 1•19 years ago
           
         | 
      ||
Jeff, you game to fix another E4X toXMLString bug?
/be
Status: UNCONFIRMED → NEW
Ever confirmed: true
| Assignee | ||
          Comment 2•19 years ago
           
         | 
      ||
(In reply to comment #1)
> Jeff, you game to fix another E4X toXMLString bug?
Sure, I'll take a stab at it.  Not sure exactly when I'll get to it, tho -- at the moment I have other, more pressing matters to process.
| Assignee | ||
          Comment 3•19 years ago
           
         | 
      ||
| Assignee | ||
          Comment 4•19 years ago
           
         | 
      ||
In the language in the spec, after outputting "<tag1" we iterate over namespaces and attributes, outputting each as needed.  For each attribute hit, we look up its namespace to get its prefix.  If the prefix is undefined, we generate a unique prefix, create a Namespace corresponding to the attribute's namespaceURI with .prefix equal to the one generated, and *add that Namespace to the set of ancestor namespaces and namespace declarations* so that we iterate over the Namespace while generating the string for the current element (and thus add " xmlns:ns='nameSpaceURI'" to the string).
In the current implementation, however, we output strings for namespaces before outputting strings for attributes.  Consequently, if we have to generate a prefix for an attribute, we create the Namespace for it and add it to the set of ancestor declarations and namespace declarations, *but we never iterate over it to output the "xmlns:ns='namespaceURI'" string* and thus produce the behavior described here.  The namespace is still added to the correct set, however, so all other behavior would still be the same.
The fix is simple: since generating attribute strings can require new namespaces to be created and declared on the element, do that before generating namespace strings.
I tested the patch against all js/tests/e4x tests; it works with no failures not present in a build created from the current tree.
          Comment 5•19 years ago
           
         | 
      ||
Comment on attachment 235859 [details] [diff] [review]
Move some code around
To quote Basil Fawlty: BRILLIANT!
You are close to becoming E4X sub-module owner :->.
/be
        Attachment #235859 -
        Flags: review?(brendan)
        Attachment #235859 -
        Flags: review+
        Attachment #235859 -
        Flags: approval1.8.1?
          Comment 6•19 years ago
           
         | 
      ||
Comment on attachment 235859 [details] [diff] [review]
Move some code around
Drivers sayz: Please land on the trunk before requesting 1.8.1approval, and also let us know if this is a JS1.7 regression or fixing an existing bug? Thanks!
        Attachment #235859 -
        Flags: approval1.8.1?
| Assignee | ||
          Comment 7•19 years ago
           
         | 
      ||
Comment on attachment 235859 [details] [diff] [review]
Move some code around
Landed on trunk.
This fixes an already-existing bug which wouldn't have been a JS1.7 regression, for the record.
        Attachment #235859 -
        Flags: approval1.8.1?
          Comment 8•19 years ago
           
         | 
      ||
Comment on attachment 235859 [details] [diff] [review]
Move some code around
a=beltzner on behalf of 181drivers
        Attachment #235859 -
        Flags: approval1.8.1? → approval1.8.1+
| Assignee | ||
          Comment 9•19 years ago
           
         | 
      ||
Fixed on branch.
          Comment 10•19 years ago
           
         | 
      ||
Checking in regress-350442.js;
/cvsroot/mozilla/js/tests/e4x/Namespace/regress-350442.js,v  <--  regress-350442.js
initial revision: 1.1
Flags: in-testsuite+
          Comment 11•19 years ago
           
         | 
      ||
verified fixed 1.8, 1.9 20060906 windows/mac*/linux
Status: RESOLVED → VERIFIED
Keywords: fixed1.8.1 → verified1.8.1
          You need to log in
          before you can comment on or make changes to this bug.
        
Description
•