Fix for bug 551412 (The EXSLT node-set function drops text nodes if they appear last in a rtf). r=sicking.
authorPeter Van der Beken <peterv@propagandism.org>
Tue, 04 May 2010 12:10:40 +0200
changeset 41757 5d60184d9e988e404541c3333ee0e916c08f1dec
parent 41756 d6bb0f9e951926d3f4f0d8ee3e70d80b408f6411
child 41758 c8c9454755d331bcd958faa2b2abb91b7f0d591e
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssicking
bugs551412
milestone1.9.3a5pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
Fix for bug 551412 (The EXSLT node-set function drops text nodes if they appear last in a rtf). r=sicking.
content/xslt/src/xslt/txEXSLTFunctions.cpp
content/xslt/src/xslt/txMozillaXMLOutput.h
content/xslt/tests/mochitest/Makefile.in
content/xslt/tests/mochitest/test_bug551412.html
--- a/content/xslt/src/xslt/txEXSLTFunctions.cpp
+++ b/content/xslt/src/xslt/txEXSLTFunctions.cpp
@@ -89,16 +89,19 @@ convertRtfToNode(txIEvalContext *aContex
     txMozillaXMLOutput mozHandler(&format, domFragment, PR_TRUE);
 
     txAXMLEventHandler* handler = &mozHandler;
     rv = aRtf->flushToHandler(&handler);
     NS_ASSERTION(handler == &mozHandler,
                  "This handler shouldn't have been replaced!");
     NS_ENSURE_SUCCESS(rv, rv);
 
+    rv = mozHandler.closePrevious(PR_TRUE);
+    NS_ENSURE_SUCCESS(rv, rv);
+
     // The txResultTreeFragment will own this.
     const txXPathNode* node = txXPathNativeNode::createXPathNode(domFragment,
                                                                  PR_TRUE);
     NS_ENSURE_TRUE(node, NS_ERROR_OUT_OF_MEMORY);
 
     aRtf->setNode(node);
 
     return NS_OK;
--- a/content/xslt/src/xslt/txMozillaXMLOutput.h
+++ b/content/xslt/src/xslt/txMozillaXMLOutput.h
@@ -101,18 +101,19 @@ public:
                        nsITransformObserver* aObserver);
     txMozillaXMLOutput(txOutputFormat* aFormat,
                        nsIDOMDocumentFragment* aFragment,
                        PRBool aNoFixup);
 
     TX_DECL_TXAXMLEVENTHANDLER
     TX_DECL_TXAOUTPUTXMLEVENTHANDLER
 
+    nsresult closePrevious(PRBool aFlushText);
+
 private:
-    nsresult closePrevious(PRBool aFlushText);
     nsresult createTxWrapper();
     nsresult startHTMLElement(nsIContent* aElement, PRBool aXHTML);
     nsresult endHTMLElement(nsIContent* aElement);
     void processHTTPEquiv(nsIAtom* aHeader, const nsString& aValue);
     nsresult createResultDocument(const nsSubstring& aName, PRInt32 aNsID,
                                   nsIDOMDocument* aSourceDocument,
                                   nsIDOMDocument* aResultDocument);
     nsresult createHTMLElement(nsIAtom* aName,
--- a/content/xslt/tests/mochitest/Makefile.in
+++ b/content/xslt/tests/mochitest/Makefile.in
@@ -45,12 +45,13 @@ include $(DEPTH)/config/autoconf.mk
 include $(topsrcdir)/config/rules.mk
 
 _TEST_FILES = 	test_bug319374.xhtml \
 		test_bug440974.html \
 		test_bug427060.html \
 		test_bug468208.html \
 		test_bug453441.html \
 		test_bug511487.html \
+		test_bug551412.html \
 		$(NULL)
 
 libs:: $(_TEST_FILES)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
new file mode 100644
--- /dev/null
+++ b/content/xslt/tests/mochitest/test_bug551412.html
@@ -0,0 +1,49 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=551412
+-->
+<head>
+  <title>Test for Bug 551412</title>
+  <script type="application/javascript" src="/MochiKit/packed.js"></script>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=551412">Mozilla Bug 551412</a>
+<p id="display"></p>
+<div id="content" style="display: none"></div>
+<pre id="test">
+<script type="application/javascript">
+
+/** Test for Bug 551412 **/
+
+  var processor = new XSLTProcessor();
+  var style =
+    '<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"' +
+                    'xmlns:exsl="http://exslt.org/common"' +
+                    'version="1.0">' +
+      '<xsl:output method="html"/>' +
+      '<xsl:variable name="rtf">1 <b>2</b> 3</xsl:variable>' +
+      '<xsl:template match="/">' +
+        '<xsl:copy-of select="exsl:node-set($rtf)"/>' +
+      '</xsl:template>' +
+    '</xsl:stylesheet>';
+  var styleDoc = new DOMParser().parseFromString (style, "text/xml");
+
+  var data =
+    '<root/>';
+  var originalDoc = new DOMParser().parseFromString(data, "text/xml");
+
+  processor.importStylesheet(styleDoc);
+
+  var fragment = processor.transformToFragment(originalDoc, document);
+  var content = document.getElementById("content");
+  content.appendChild(fragment);
+  is(content.innerHTML, "1 <b>2</b> 3",
+     "Result of transform should be '1 <b>2</b> 3'");
+
+</script>
+</pre>
+</body>
+</html>