+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).
--- /dev/null
+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
--- /dev/null
+<!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>
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: <<<&тест&>>>
-</body></html>
+ CHARACTERS IN XSLT: ééééééééééé <br><br>SOURCE XML: <<<&тест&>>></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: <<<&тест&>>>
-SOURCE XML: <<<&тест&>>>
-</pre>
+SOURCE XML: <<<&тест&>>></pre>
</body>
</html>
1.3 Import undefined stylesheet:
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
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
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
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
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: " "
+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.
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;
}
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)