Open Bug 502177 Opened 15 years ago Updated 3 years ago

nsIDocumentEncoder : Wrong serialization with fixupNode

Categories

(Core :: DOM: Serializers, defect, P5)

x86
Windows XP
defect

Tracking

()

UNCONFIRMED

People

(Reporter: sylvain.spinelli, Unassigned)

References

Details

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.9.1) Gecko/20090624 Firefox/3.5 (.NET CLR 3.5.30729)
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.9.1) Gecko/20090624 Firefox/3.5 (.NET CLR 3.5.30729)

If I return a different node with nsIDocumentEncoder.setNodeFixup(), the serialization of the end tag do not use the fixUp node but the original one.

Reproducible: Always

Steps to Reproduce:
1. create a file like this :
----------------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<title>testBugSerializer.html</title>
		<script>
		function serializeXhtml(){
			try{ 
	   			netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
	    		var vEncoder = Components.classes["@mozilla.org/layout/documentEncoder;1?type=application/xhtml+xml"].createInstance(Components.interfaces.nsIDocumentEncoder);
	    		vEncoder.init(document, "application/xhtml+xml", 0);
	    		vEncoder.setContainerNode(document.body); 
	    		var vFixUp = {
	    			fixupNode : function(pNode, pSerializeCloneKids){
	    				if(pNode.nodeType==1 && ! pNode.namespaceUri) {
	    					var vNewNode = pNode.ownerDocument.createElementNS("http://www.w3.org/1999/xhtml", "xhtml:"+pNode.nodeName.toLowerCase());
	    					return vNewNode;
	    				}
	    				return null;
	    			} 
	    		};
	    		vEncoder.setNodeFixup(vFixUp);
	    		var vResult = vEncoder.encodeToString(); 
	    		alert("RESULT::::"+vResult); 
	    	} catch(e){alert("FAILED:::"+e)}
		}
		</script>
	</head>
	
	<body>
		<div>abcdefghijklmopqrstuvwxyz</div>
		<button onclick="serializeXhtml()">serializeXhtml</button>
	</body>
</html>
-----------------------------------------------

2. click on "serializeXhtml" button
3. the alert message show a wrong serialization with an open "<xhtml:div>" tag and a closed "</DIV>" tag.
Actual Results:  
 <xhtml:div xmlns:xhtml="http://www.w3.org/1999/xhtml">abcdefghijklmopqrstuvwxyz</DIV>
<xhtml:button xmlns:xhtml="http://www.w3.org/1999/xhtml">serializeXhtml</BUTTON>  

Expected Results:  
 <xhtml:div xmlns:xhtml="http://www.w3.org/1999/xhtml">abcdefghijklmopqrstuvwxyz</xhtml:div>  <xhtml:button xmlns:xhtml="http://www.w3.org/1999/xhtml">serializeXhtml</xhtml:button>
Component: General → Serializers
Product: Firefox → Core
I just runned your example with a nightly. This bug does not exists any more on the trunk (and probably on 1.9.2 branch too), certainly since my improvements on the serializer (bug 422403), or perhaps because of improvements on HTML5 implementation (tagName of HTML elements are now in lowercase, and they have a namespace http://www.w3.org/1999/xhtml)
Status: UNCONFIRMED → RESOLVED
Closed: 15 years ago
Depends on: 422403
Resolution: --- → FIXED
Exact, the problem does not appear in 1.9.2 with my test-case, because of improvements on HTML5 implementation (tagName of HTML elements are now in lowercase, and they have a namespace http://www.w3.org/1999/xhtml).

But if you change my test case, the fixupNode bug is still here. For example :

--------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <title>testBugSerializer.html</title>
        <script>
        function serializeXhtml(){
            try{ 
                  
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
                var vEncoder =
Components.classes["@mozilla.org/layout/documentEncoder;1?type=application/xhtml+xml"].createInstance(Components.interfaces.nsIDocumentEncoder);
                vEncoder.init(document, "application/xhtml+xml", 0);
                vEncoder.setContainerNode(document.body); 
                var vFixUp = {
                    fixupNode : function(pNode, pSerializeCloneKids){
                        if(pNode.nodeType==1) {
                            var vNewNode =
pNode.ownerDocument.createElementNS("aaa",
"a:XX"+pNode.localName);
                            return vNewNode;
                        }
                        return null;
                    } 
                };
                vEncoder.setNodeFixup(vFixUp);
                var vResult = vEncoder.encodeToString(); 
                alert("RESULT::::"+vResult); 
            } catch(e){alert("FAILED:::"+e)}
        }
        </script>
    </head>

    <body>
        <div>abcdefghijklmopqrstuvwxyz</div>
        <button onclick="serializeXhtml()">serializeXhtml</button>
    </body>
</html>
--------------------------
Status: RESOLVED → UNCONFIRMED
Resolution: FIXED → ---
QA Contact: general → dom-to-text

Bulk-downgrade of unassigned, >=5 years untouched DOM/Storage bugs' priority.

If you have reason to believe this is wrong (especially for the severity), please write a comment and ni :jstutte.

Severity: normal → S4
Priority: -- → P5
You need to log in before you can comment on or make changes to this bug.