From eb5f21553c13a591f2e48d95bd4505941f51db8b Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Tue, 18 Sep 2001 09:56:57 +0000 Subject: [PATCH] fixed bug #60624 improver the error context reporting added a specific * libxslt/xslt.c: fixed bug #60624 * libxslt/xsltutils.c: improver the error context reporting * tests/reports/Makefile.am tests/reports/tst-2.*: added a specific regression test * xsltproc/xsltproc: free the stylesheet if it contained an error. Daniel --- ChangeLog | 8 ++++++++ libxslt/xslt.c | 12 +++++++++++- libxslt/xsltutils.c | 9 +++++++++ tests/reports/Makefile.am | 5 +++-- tests/reports/tst-2.err | 6 ++++++ tests/reports/tst-2.out | 0 tests/reports/tst-2.xml | 1 + tests/reports/tst-2.xsl | 10 ++++++++++ xsltproc/xsltproc.c | 3 ++- 9 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 tests/reports/tst-2.err create mode 100644 tests/reports/tst-2.out create mode 100644 tests/reports/tst-2.xml create mode 100644 tests/reports/tst-2.xsl diff --git a/ChangeLog b/ChangeLog index 522b221..ba1ed5b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Tue Sep 18 11:48:20 CEST 2001 Daniel Veillard + + * libxslt/xslt.c: fixed bug #60624 + * libxslt/xsltutils.c: improver the error context reporting + * tests/reports/Makefile.am tests/reports/tst-2.*: added a + specific regression test + * xsltproc/xsltproc: free the stylesheet if it contained an error. + Mon Sep 17 14:45:48 CEST 2001 Daniel Veillard * libxslt/variables.c: fixed a problem with global var override diff --git a/libxslt/xslt.c b/libxslt/xslt.c index b4ff588..62cb1bd 100644 --- a/libxslt/xslt.c +++ b/libxslt/xslt.c @@ -1693,6 +1693,16 @@ xsltParseStylesheetTop(xsltStylesheetPtr style, xmlNodePtr top) { cur = cur->next; continue; } + if (cur->type == XML_TEXT_NODE) { + if (cur->content != NULL) { + xsltPrintErrorContext(NULL, style, cur); + xsltGenericError(xsltGenericErrorContext, + "misplaced text element: '%s'\n", cur->content); + } + style->errors++; + cur = cur->next; + continue; + } if ((cur->type == XML_ELEMENT_NODE) && (cur->ns == NULL)) { xsltGenericError(xsltGenericErrorContext, "Found a top-level element %s with null namespace URI\n", @@ -1701,7 +1711,7 @@ xsltParseStylesheetTop(xsltStylesheetPtr style, xmlNodePtr top) { cur = cur->next; continue; } - if (!(IS_XSLT_ELEM(cur))) { + if ((cur->type == XML_ELEMENT_NODE) && (!(IS_XSLT_ELEM(cur)))) { xsltTopLevelFunction function; function = xsltExtModuleTopLevelLookup(cur->name, diff --git a/libxslt/xsltutils.c b/libxslt/xsltutils.c index 5edecda..9b55c69 100644 --- a/libxslt/xsltutils.c +++ b/libxslt/xsltutils.c @@ -298,8 +298,17 @@ xsltPrintErrorContext(xsltTransformContextPtr ctxt, file = doc->URL; } else { + /* + * Try to find contextual informations to report + */ if (node->type == XML_ELEMENT_NODE) { line = (int) node->content; + } else if ((node->prev != NULL) && + (node->prev->type == XML_ELEMENT_NODE)) { + line = (int) node->prev->content; + } else if ((node->parent != NULL) && + (node->parent->type == XML_ELEMENT_NODE)) { + line = (int) node->parent->content; } if ((node->doc != NULL) && (node->doc->URL != NULL)) file = node->doc->URL; diff --git a/tests/reports/Makefile.am b/tests/reports/Makefile.am index 75a4f29..8168249 100644 --- a/tests/reports/Makefile.am +++ b/tests/reports/Makefile.am @@ -4,7 +4,8 @@ $(top_builddir)/xsltproc/xsltproc: @(cd ../../xsltproc ; $(MAKE) xsltproc) EXTRA_DIST = \ - tst-1.xml tst-1.xsl tst-1.out tst-1.err + tst-1.xml tst-1.xsl tst-1.out tst-1.err \ + tst-2.xml tst-2.xsl tst-2.out tst-2.err all: test @@ -14,7 +15,7 @@ test tests: $(top_builddir)/xsltproc/xsltproc @(for i in $(srcdir)/*.xml ; do \ if [ -d $$i ] ; then continue ; fi ; \ doc=`basename $$i .xml` ; \ - for j in $(srcdir)/$$doc*.xsl ; do \ + for j in $(srcdir)/$$doc.xsl ; do \ if [ ! -f $$j ] ; then continue ; fi ; \ if [ -d $$j ] ; then continue ; fi ; \ name=`basename $$j .xsl`; \ diff --git a/tests/reports/tst-2.err b/tests/reports/tst-2.err new file mode 100644 index 0000000..d144c49 --- /dev/null +++ b/tests/reports/tst-2.err @@ -0,0 +1,6 @@ +compilation error: file ./tst-2.xsl line 2 element text +misplaced text element: ' + +a not allowed top level element + +' diff --git a/tests/reports/tst-2.out b/tests/reports/tst-2.out new file mode 100644 index 0000000..e69de29 diff --git a/tests/reports/tst-2.xml b/tests/reports/tst-2.xml new file mode 100644 index 0000000..69d62f2 --- /dev/null +++ b/tests/reports/tst-2.xml @@ -0,0 +1 @@ + diff --git a/tests/reports/tst-2.xsl b/tests/reports/tst-2.xsl new file mode 100644 index 0000000..98fa6c9 --- /dev/null +++ b/tests/reports/tst-2.xsl @@ -0,0 +1,10 @@ + + + +a not allowed top level element + + + + + + diff --git a/xsltproc/xsltproc.c b/xsltproc/xsltproc.c index e757835..cfe31f4 100644 --- a/xsltproc/xsltproc.c +++ b/xsltproc/xsltproc.c @@ -618,8 +618,9 @@ main(int argc, char **argv) } xsltProcess(doc, cur, argv[i]); } - xsltFreeStylesheet(cur); } + if (cur != NULL) + xsltFreeStylesheet(cur); done: xsltCleanupGlobals(); xmlCleanupParser(); -- 2.7.4