WebCore:
authorandersca <andersca@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 21 Jul 2006 07:52:10 +0000 (07:52 +0000)
committerandersca <andersca@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 21 Jul 2006 07:52:10 +0000 (07:52 +0000)
2006-07-20  Anders Carlsson  <acarlsson@apple.com>

        Reviewed by Geoff.

        <rdar://problem/4637807> REGRESSION: "Features & Options" page at volvocars.us fails

        * xml/XSLTProcessor.cpp:
        (WebCore::xsltParamArrayFromParameterMap):
        Turns out parameters never worked. String parameters need to be escaped so we create a transform context,
        add the parameters to it quoted and then use xsltApplyStylesheetUser which lets us pass the transform context to it.
        This also works around a bug in libxslt where a hash table isn't allocated.

LayoutTests:

2006-07-20  Anders Carlsson  <acarlsson@apple.com>

        Reviewed by Geoff.

        <rdar://problem/4637807> REGRESSION: "Features & Options" page at volvocars.us fails

        * fast/xsl/xslt-processer-expected.txt:
        This passes now.

        * fast/xsl/xslt-string-parameters-expected.txt: Added.
        * fast/xsl/xslt-string-parameters.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/fast/xsl/xslt-processer-expected.txt
LayoutTests/fast/xsl/xslt-string-parameters-expected.txt [new file with mode: 0644]
LayoutTests/fast/xsl/xslt-string-parameters.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/xml/XSLTProcessor.cpp

index d30e93d686bba16144402f4978abe6785902e4eb..f4f6f674e410583424398d2c3d6193afabf83638 100644 (file)
@@ -1,3 +1,15 @@
+2006-07-20  Anders Carlsson  <acarlsson@apple.com>
+
+        Reviewed by Geoff.
+
+        <rdar://problem/4637807> REGRESSION: "Features & Options" page at volvocars.us fails
+        
+        * fast/xsl/xslt-processer-expected.txt:
+        This passes now.
+        
+        * fast/xsl/xslt-string-parameters-expected.txt: Added.
+        * fast/xsl/xslt-string-parameters.html: Added.
+
 2006-07-20  Maciej Stachowiak  <mjs@apple.com>
 
         Reviewed by Beth and John.
index 0d381614de66ed72046127f18e3ad9a926cc52f4..1fb228b255a4e2ce450a941f6a9eb9e63fb4824c 100644 (file)
@@ -66,9 +66,9 @@ Success
 2.4 transform to same fragment twice:
 Success
 2.5 transformed fragment containing only text:
-****Failure**** (expected: "SUCCESS" actual: "")
+Success
 2.6 fragment using passed parameters:
-****Failure**** (expected: "SUCCESS" actual: "")
+Success
 
 3.0 DOMDocument transformToDocument(in DOMNode source):
 
diff --git a/LayoutTests/fast/xsl/xslt-string-parameters-expected.txt b/LayoutTests/fast/xsl/xslt-string-parameters-expected.txt
new file mode 100644 (file)
index 0000000..585bf02
--- /dev/null
@@ -0,0 +1,4 @@
+This tests that passing string parameters to the XSLTProcessor works as expected. If this test is successful, the text "SUCCESS" will be shown below.
+
+SUCCESS
+
diff --git a/LayoutTests/fast/xsl/xslt-string-parameters.html b/LayoutTests/fast/xsl/xslt-string-parameters.html
new file mode 100644 (file)
index 0000000..a463c70
--- /dev/null
@@ -0,0 +1,39 @@
+<html>
+<head>
+    <script>
+        function runTest() {
+            if (window.layoutTestController)
+                layoutTestController.dumpAsText();
+                
+            var sourceDoc = (new DOMParser).parseFromString('<test/>', 'text/xml');
+            var sheetDoc = (new DOMParser).parseFromString('<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">' +
+                                                           '<xsl:output method="text"/><xsl:param name="testParam"/>' + 
+                                                           '<xsl:template match="/test"><xsl:value-of select="$testParam"/></xsl:template></xsl:stylesheet>', 'text/xml');
+                                                           
+            var processor = new XSLTProcessor();
+            processor.importStylesheet(sheetDoc);
+
+            processor.setParameter(null, 'testParam', 'text')
+            var result = processor.transformToFragment(sourceDoc, document);
+            if (result.textContent != 'text')
+                return;
+
+            processor.setParameter(null, 'testParam', 'text with spaces')
+            var result = processor.transformToFragment(sourceDoc, document);
+            if (result.textContent != 'text with spaces')
+                return;
+            processor.setParameter(null, 'testParam', 'Shakespeare\'s "Twelfth Night"')
+            var result = processor.transformToFragment(sourceDoc, document);
+            if (result.textContent != 'Shakespeare\'s "Twelfth Night"')
+                return;
+            
+            document.getElementById('result').innerHTML = 'SUCCESS';
+        }
+    </script>
+</head>
+<body onload="runTest()">
+    <p>This tests that passing string parameters to the XSLTProcessor works as expected. If this test is successful, the text "SUCCESS" will be shown below.</p>
+    <div id="result">FAILURE</div>
+</body>
+</html>
index 663d9243a1ae5f9a59cfa3795ef9e648a447a2c4..edaca43d1ec0be6a9c41036df581f604cb0db473 100644 (file)
@@ -1,3 +1,15 @@
+2006-07-20  Anders Carlsson  <acarlsson@apple.com>
+
+        Reviewed by Geoff.
+
+        <rdar://problem/4637807> REGRESSION: "Features & Options" page at volvocars.us fails
+
+        * xml/XSLTProcessor.cpp:
+        (WebCore::xsltParamArrayFromParameterMap):
+        Turns out parameters never worked. String parameters need to be escaped so we create a transform context,
+        add the parameters to it quoted and then use xsltApplyStylesheetUser which lets us pass the transform context to it.
+        This also works around a bug in libxslt where a hash table isn't allocated.
+
 2006-07-20  Alice Liu  <alice.liu@apple.com>
 
         Reviewed by Tim Omernick.
index e66384c0204a4950b6c216bdd8674f4cbd1c173c..b00f7e5eecdd543c14bd647106f5b76369dce148 100644 (file)
@@ -40,6 +40,7 @@
 #include "markup.h"
 #include <wtf/Vector.h>
 #include <libxslt/imports.h>
+#include <libxslt/variables.h>
 #include <libxslt/xsltutils.h>
 
 namespace WebCore {
@@ -305,9 +306,20 @@ bool XSLTProcessor::transformToString(Node *sourceNode, DeprecatedString &mimeTy
     bool success = false;
     bool shouldFreeSourceDoc = false;
     if (xmlDocPtr sourceDoc = xmlDocPtrFromNode(sourceNode, shouldFreeSourceDoc)) {
+        xsltTransformContextPtr transformContext = xsltNewTransformContext(sheet, sourceDoc);
+
+        // This is a workaround for a bug in libxslt. 
+        // The bug has been fixed in version 1.1.13, so once we ship that this can be removed.
+        if (transformContext->globalVars == NULL)
+           transformContext->globalVars = xmlHashCreate(20);
+
         const char **params = xsltParamArrayFromParameterMap(m_parameters);
-        xmlDocPtr resultDoc = xsltApplyStylesheet(sheet, sourceDoc, params);
+        xsltQuoteUserParams(transformContext, params);
+        xmlDocPtr resultDoc = xsltApplyStylesheetUser(sheet, sourceDoc, 0, 0, 0, transformContext);
+        
+        xsltFreeTransformContext(transformContext);        
         freeXsltParamArray(params);
+        
         if (shouldFreeSourceDoc)
             xmlFreeDoc(sourceDoc);