If you think a bug might affect users in the 57 release, please set the correct tracking and status flags for Release Management.

nsIDocumentEncoder : Wrong serialization with fixupNode

UNCONFIRMED
Unassigned

Status

()

Core
Serializers
UNCONFIRMED
8 years ago
8 years ago

People

(Reporter: Sylvain Spinelli, Unassigned)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

8 years ago
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>
(Reporter)

Updated

8 years ago
Component: General → Serializers
Product: Firefox → Core

Comment 1

8 years ago
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
Last Resolved: 8 years ago
Depends on: 422403
Resolution: --- → FIXED
(Reporter)

Comment 2

8 years ago
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
You need to log in before you can comment on or make changes to this bug.