[Lxml-checkins] r53795 - in lxml/branch/lxml-2.0: . src/lxml src/lxml/tests
scoder at codespeak.net
scoder at codespeak.net
Tue Apr 15 20:28:48 CEST 2008
Author: scoder
Date: Tue Apr 15 20:28:46 2008
New Revision: 53795
Modified:
lxml/branch/lxml-2.0/CHANGES.txt
lxml/branch/lxml-2.0/src/lxml/tests/test_xslt.py
lxml/branch/lxml-2.0/src/lxml/xslt.pxd
lxml/branch/lxml-2.0/src/lxml/xslt.pxi
Log:
trunk merge -c 53787: XSLT error handling
Modified: lxml/branch/lxml-2.0/CHANGES.txt
==============================================================================
--- lxml/branch/lxml-2.0/CHANGES.txt (original)
+++ lxml/branch/lxml-2.0/CHANGES.txt Tue Apr 15 20:28:46 2008
@@ -13,6 +13,9 @@
* Resolving to a filename in custom resolvers didn't work.
+* lxml did not honour libxslt's second error state "STOPPED", which
+ let some XSLT errors pass silently.
+
* Memory leak in Schematron with libxml2 >= 2.6.31.
Other changes
Modified: lxml/branch/lxml-2.0/src/lxml/tests/test_xslt.py
==============================================================================
--- lxml/branch/lxml-2.0/src/lxml/tests/test_xslt.py (original)
+++ lxml/branch/lxml-2.0/src/lxml/tests/test_xslt.py Tue Apr 15 20:28:46 2008
@@ -276,6 +276,23 @@
''',
st.tostring(res))
+ def test_xslt_parameter_invalid(self):
+ tree = self.parse('<a><b>B</b><c>C</c></a>')
+ style = self.parse('''\
+<xsl:stylesheet version="1.0"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+ <xsl:param name="bar"/>
+ <xsl:template match="/">
+ <foo><xsl:value-of select="$bar" /></foo>
+ </xsl:template>
+</xsl:stylesheet>''')
+
+ st = etree.XSLT(style)
+ res = self.assertRaises(etree.XSLTApplyError,
+ st, tree, bar="<test/>")
+ res = self.assertRaises(etree.XSLTApplyError,
+ st, tree, bar="....")
+
if etree.LIBXSLT_VERSION < (1,1,18):
# later versions produce no error
def test_xslt_parameter_missing(self):
@@ -482,9 +499,8 @@
source = self.parse(xml)
styledoc = self.parse(xslt)
style = etree.XSLT(styledoc)
- result = style.apply(source)
- self.assertEqual('', style.tostring(result))
- self.assertEqual('', str(result))
+
+ self.assertRaises(etree.XSLTApplyError, style, source)
self.assert_("TEST TEST TEST" in [entry.message
for entry in style.error_log])
Modified: lxml/branch/lxml-2.0/src/lxml/xslt.pxd
==============================================================================
--- lxml/branch/lxml-2.0/src/lxml/xslt.pxd (original)
+++ lxml/branch/lxml-2.0/src/lxml/xslt.pxd Tue Apr 15 20:28:46 2008
@@ -8,6 +8,11 @@
cdef int LIBXSLT_VERSION
cdef extern from "libxslt/xsltInternals.h":
+ ctypedef enum xsltTransformState:
+ XSLT_STATE_OK # 0
+ XSLT_STATE_ERROR # 1
+ XSLT_STATE_STOPPED # 2
+
ctypedef struct xsltDocument:
xmlDoc* doc
@@ -22,6 +27,7 @@
void* _private
xmlDict* dict
int profile
+ xsltTransformState state
cdef xsltStylesheet* xsltParseStylesheetDoc(xmlDoc* doc) nogil
cdef void xsltFreeStylesheet(xsltStylesheet* sheet) nogil
Modified: lxml/branch/lxml-2.0/src/lxml/xslt.pxi
==============================================================================
--- lxml/branch/lxml-2.0/src/lxml/xslt.pxi (original)
+++ lxml/branch/lxml-2.0/src/lxml/xslt.pxi Tue Apr 15 20:28:46 2008
@@ -420,6 +420,11 @@
c_result = self._run_transform(
c_doc, _kw, context, transform_ctxt)
+ if transform_ctxt.state != xslt.XSLT_STATE_OK:
+ if c_result is not NULL:
+ tree.xmlFreeDoc(c_result)
+ c_result = NULL
+
if transform_ctxt.profile:
c_profile_doc = xslt.xsltGetProfileInformation(transform_ctxt)
if c_profile_doc is not NULL:
More information about the lxml-checkins
mailing list