Reviewed by Maciej.
authorap@webkit.org <ap@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 25 Nov 2007 09:45:09 +0000 (09:45 +0000)
committerap@webkit.org <ap@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 25 Nov 2007 09:45:09 +0000 (09:45 +0000)
        http://bugs.webkit.org/show_bug.cgi?id=15919
        XSLTProcessor.transformToFragment creates an extra not defined TEXT_NODE at the end

        Test: fast/xsl/extra-lf-at-end.html

        * xml/XSLTProcessor.cpp:
        (WebCore::writeToVector): Changed to use Vector to avoid slow String::apend().
        (WebCore::saveResultToString): Remove trailing line feed if present.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@28014 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/xsl/extra-lf-at-end-expected.txt [new file with mode: 0644]
LayoutTests/fast/xsl/extra-lf-at-end.html [new file with mode: 0644]
LayoutTests/fast/xsl/xslt-processor-expected.txt
LayoutTests/platform/mac/fast/xsl/xslt-enc-cyr-expected.txt
LayoutTests/platform/mac/fast/xsl/xslt-enc-expected.txt
LayoutTests/platform/mac/fast/xsl/xslt-enc16-expected.txt
LayoutTests/platform/mac/fast/xsl/xslt-enc16to16-expected.txt
LayoutTests/platform/mac/fast/xsl/xslt-text-expected.txt
WebCore/ChangeLog
WebCore/xml/XSLTProcessor.cpp

index 8b263bdf21dd2677e0308fa17ac7a6e79c235497..9d9c85b69c7d6912bf6425bd3b7acd2b48bc7669 100644 (file)
@@ -1,3 +1,19 @@
+2007-11-25  Alexey Proskuryakov  <ap@webkit.org>
+
+        Reviewed by Maciej.
+
+        http://bugs.webkit.org/show_bug.cgi?id=15919
+        XSLTProcessor.transformToFragment creates an extra not defined TEXT_NODE at the end
+
+        * fast/xsl/extra-lf-at-end-expected.txt: Added.
+        * fast/xsl/extra-lf-at-end.html: Added.
+        * fast/xsl/xslt-processor-expected.txt:
+        * platform/mac/fast/xsl/xslt-enc-cyr-expected.txt:
+        * platform/mac/fast/xsl/xslt-enc-expected.txt:
+        * platform/mac/fast/xsl/xslt-enc16-expected.txt:
+        * platform/mac/fast/xsl/xslt-enc16to16-expected.txt:
+        * platform/mac/fast/xsl/xslt-text-expected.txt:
+
 2007-11-24  David D. Kilzer  <ddkilzer@webkit.org>
 
         Added tests for select.options.remove(boolean).
diff --git a/LayoutTests/fast/xsl/extra-lf-at-end-expected.txt b/LayoutTests/fast/xsl/extra-lf-at-end-expected.txt
new file mode 100644 (file)
index 0000000..9448b1f
--- /dev/null
@@ -0,0 +1,8 @@
+Test for bug 15919: XSLTProcessor.transformToFragment creates an extra not defined TEXT_NODE at the end.
+
+PASS: oResult.nodeType should of type DOCUMENT_FRAGMENT_NODE(11)
+PASS: oProc.getParameter(null, 'text') getParameter should return the correct value
+PASS: oResult.firstChild.nodeName can have multiple children, firstchild should be the div
+PASS: oResult.lastChild.nodeName can have multiple children, lastchild should be the br
+PASS: oResult.firstChild.textContent || oResult.firstChild.text textContent should be set to parameter value
+Done
diff --git a/LayoutTests/fast/xsl/extra-lf-at-end.html b/LayoutTests/fast/xsl/extra-lf-at-end.html
new file mode 100644 (file)
index 0000000..d813998
--- /dev/null
@@ -0,0 +1,58 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+    <head>
+        <title>bug 15919</title>
+    </head>
+    <body>
+        <p>Test for <a href="http://bugs.webkit.org/show_bug.cgi?id=15919">bug 15919</a>:
+        XSLTProcessor.transformToFragment creates an extra not defined TEXT_NODE at the end.</p>
+        <div id="log"></div>
+
+        <script type="text/javascript">
+
+            if (window.layoutTestController)
+                layoutTestController.dumpAsText();
+
+            function log(message) {
+                var newChild = document.createElement("div");
+                newChild.appendChild(document.createTextNode(message));
+                document.getElementById("log").appendChild(newChild);
+            }
+
+            function assertEquals(oExpected, oExpr, sWarning) {
+                oActual = eval(oExpr);
+                if(oExpected !== oActual)
+                    log('FAIL: Expected "'+ oExpected+'" was: "'+oActual+'" - '+sWarning);
+                else
+                    log('PASS: ' + oExpr + ' ' + sWarning);
+            }
+
+            var oProc = new XSLTProcessor();
+
+            var oStylesheet = new DOMParser().parseFromString(
+            '<?xml version="1.0" encoding="UTF-8"?>' +
+            '<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">'+
+                '<xsl:output method="xml" omit-xml-declaration="yes" />'+
+                '<xsl:param name="text" select="\'default\'" />'+
+                '<xsl:template match="/">'+
+                    '<div><xsl:value-of select="$text" /></div>'+
+                    '<br />'+
+                '</xsl:template>'+
+            '</xsl:stylesheet>', 'text/xml');
+
+            oProc.importStylesheet(oStylesheet);
+            var oResult = new DOMParser().parseFromString('<root />', 'text/xml');
+
+            oProc.setParameter('', 'text', 'Hello World!');
+
+            oResult = oProc.transformToFragment(oStylesheet, oResult);
+
+            assertEquals(11, "oResult.nodeType", 'should of type DOCUMENT_FRAGMENT_NODE(11)')
+            assertEquals('Hello World!', "oProc.getParameter(null, 'text')", 'getParameter should return the correct value');
+            assertEquals('div', "oResult.firstChild.nodeName", 'can have multiple children, firstchild should be the div');
+            assertEquals('br', "oResult.lastChild.nodeName", 'can have multiple children, lastchild should be the br');
+            assertEquals('Hello World!', "oResult.firstChild.textContent || oResult.firstChild.text", 'textContent should be set to parameter value');
+            log("Done");
+        </script>
+    </body>
+</html>
index 55fd6b436319837ae2d209c051dc65d11ba008ba..5264426a3d79f8d68705dee75722af47d7da6104 100644 (file)
 
 1.1 Import two different stylesheets:
 <html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head><body>
-              CHARACTERS IN XSLT: ééééééééééé <br><br>SOURCE XML: &lt;&lt;&lt;&amp;тест&amp;>>>
-</body></html>
+              CHARACTERS IN XSLT: ééééééééééé <br><br>SOURCE XML: &lt;&lt;&lt;&amp;тест&amp;>>></body></html>
 1.2 Import same stylesheet twice:
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
 <head><title></title></head>
 <body>
 <pre>CHARACTERS IN XSLT: &lt;&lt;&lt;&amp;тест&amp;>>>
-SOURCE XML: &lt;&lt;&lt;&amp;тест&amp;>>>
-</pre>
+SOURCE XML: &lt;&lt;&lt;&amp;тест&amp;>>></pre>
 </body>
 </html>
 1.3 Import undefined stylesheet:
index b3d1de74aff586a493e70f5f375f2a5542ccd2f8..bf7501b56a4f6acecaf4dff8a8b8b6c8b42633e9 100644 (file)
@@ -9,4 +9,3 @@ layer at (0,0) size 800x70
       RenderBR {BR} at (0,18) size 0x18
       RenderText {#text} at (0,36) size 222x18
         text run at (0,36) width 222: "SOURCE XML: \x{418}\x{441}\x{445}\x{43E}\x{434}\x{43D}\x{44B}\x{439} \x{442}\x{435}\x{43A}\x{441}\x{442}"
-      RenderText {#text} at (0,0) size 0x0
index 4273aca00e504aead397e37483c119f4f89bc631..a12332395162b9db4bd1468c1c3e82c8fb18054a 100644 (file)
@@ -9,4 +9,3 @@ layer at (0,0) size 800x70
       RenderBR {BR} at (0,18) size 0x18
       RenderText {#text} at (0,36) size 316x18
         text run at (0,36) width 316: "SOURCE XML: \x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}"
-      RenderText {#text} at (0,0) size 0x0
index 4273aca00e504aead397e37483c119f4f89bc631..a12332395162b9db4bd1468c1c3e82c8fb18054a 100644 (file)
@@ -9,4 +9,3 @@ layer at (0,0) size 800x70
       RenderBR {BR} at (0,18) size 0x18
       RenderText {#text} at (0,36) size 316x18
         text run at (0,36) width 316: "SOURCE XML: \x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}"
-      RenderText {#text} at (0,0) size 0x0
index 4273aca00e504aead397e37483c119f4f89bc631..a12332395162b9db4bd1468c1c3e82c8fb18054a 100644 (file)
@@ -9,4 +9,3 @@ layer at (0,0) size 800x70
       RenderBR {BR} at (0,18) size 0x18
       RenderText {#text} at (0,36) size 316x18
         text run at (0,36) width 316: "SOURCE XML: \x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}\x{E9}"
-      RenderText {#text} at (0,0) size 0x0
index f094c46ba65adb307d805b30ec8a40859d1e45ce..d79370ee98c0a5ab0e9a10274a80057e09c13ea0 100644 (file)
@@ -8,4 +8,3 @@ layer at (0,0) size 800x56
           text run at (0,0) width 256: "CHARACTERS IN XSLT: <<<&\x{442}\x{435}\x{441}\x{442}&>>>"
           text run at (256,0) width 0: " "
           text run at (0,15) width 192: "SOURCE XML: <<<&\x{442}\x{435}\x{441}\x{442}&>>>"
-          text run at (192,15) width 0: " "
index b047bd2f66670296f9f3b18499a373c068a01bc3..a6303b8cd16b05ab6b05bdfdab323db8331724f7 100644 (file)
@@ -1,3 +1,16 @@
+2007-11-25  Alexey Proskuryakov  <ap@webkit.org>
+
+        Reviewed by Maciej.
+
+        http://bugs.webkit.org/show_bug.cgi?id=15919
+        XSLTProcessor.transformToFragment creates an extra not defined TEXT_NODE at the end
+
+        Test: fast/xsl/extra-lf-at-end.html
+
+        * xml/XSLTProcessor.cpp:
+        (WebCore::writeToVector): Changed to use Vector to avoid slow String::apend().
+        (WebCore::saveResultToString): Remove trailing line feed if present.
+
 2007-11-24  Mark Rowe  <mrowe@apple.com>
 
         Reviewed by Tim Hatcher.
index 660e2d7722a6cb54664fd1a921fdc06cbf76920f..74f84c22f474480ede7706af6d8234ec00a40741 100644 (file)
@@ -151,10 +151,11 @@ static inline void setXSLTLoadCallBack(xsltDocLoaderFunc func, XSLTProcessor* pr
     globalDocLoader = loader;
 }
 
-static int writeToString(void* context, const char* buffer, int len)
+static int writeToVector(void* context, const char* buffer, int len)
 {
-    String& resultOutput = *static_cast<String*>(context);
-    resultOutput += String::fromUTF8(buffer, len);
+    Vector<UChar>& resultOutput = *static_cast<Vector<UChar>*>(context);
+    String decodedChunk = String::fromUTF8(buffer, len);
+    resultOutput.append(decodedChunk.characters(), decodedChunk.length());
     return len;
 }
 
@@ -163,13 +164,23 @@ static bool saveResultToString(xmlDocPtr resultDoc, xsltStylesheetPtr sheet, Str
     xmlOutputBufferPtr outputBuf = xmlAllocOutputBuffer(0);
     if (!outputBuf)
         return false;
-    outputBuf->context = &resultString;
-    outputBuf->writecallback = writeToString;
+
+    Vector<UChar> resultVector;
+    outputBuf->context = &resultVector;
+    outputBuf->writecallback = writeToVector;
     
     int retval = xsltSaveResultTo(outputBuf, resultDoc, sheet);
     xmlOutputBufferClose(outputBuf);
-    
-    return (retval >= 0);
+    if (retval < 0)
+        return false;
+
+    // Workaround for <http://bugzilla.gnome.org/show_bug.cgi?id=495668>: libxslt appends an extra line feed to the result.
+    if (resultVector.size() > 0 && resultVector[resultVector.size() - 1] == '\n')
+        resultVector.removeLast();
+
+    resultString = String::adopt(resultVector);
+
+    return true;
 }
 
 static inline void transformTextStringToXHTMLDocumentString(String& text)