Re: [xslt] xsl:template without name and match attributes should not be allowed



On Wed, Jun 12, 2019 at 10:49:15PM +0200, Nikolai Weibull via xslt wrote:
Hi!

It seems that libxslt allows for an xsl:template to be created without name or match attribute.  This isn’t 
allowed by the standard and sometimes my colleagues forget and then wonder why things don’t work :-).

A simple check in xsltAddTemplate would suffice, for example,

  Hi,

indeed, that looks like a bug I just pushed the patch before cutting
1.1.34 Release Candidate 2 

diff --git a/libxslt/pattern.c b/libxslt/pattern.c
index 32de1b48..597b6b44 100644
--- a/libxslt/pattern.c
+++ b/libxslt/pattern.c
@@ -2131,8 +2131,15 @@ xsltAddTemplate(xsltStylesheetPtr style, xsltTemplatePtr cur,
         xmlHashAddEntry2(style->namedTemplates, cur->name, cur->nameURI, cur);
     }
 
-    if (cur->match == NULL)
+    if (cur->match == NULL) {
+            if (cur->name == NULL) {
+                xsltTransformError(NULL, style, cur->elem,
+                    "xsl:template: need to specify match or name attribute\n");
+                style->errors++;
+                return(-1);
+            }
      return(0);
+    }
 
     priority = cur->priority;
     pat = xsltCompilePatternInternal(cur->match, style->doc, cur->elem,

but I couldn’t quite figure out the structure of the tests directory, so I didn’t write a test for this.  
Any help in this area would be appreciated.

  Ah, that's simple, in tests/gneral since that affects the general work
of the engine, allocate a new bug number, create the xsl and xml reproducing
it, run xsltproc from the code after having fixed the bug i.e. with proper
behaviour, then save the stdout to .out, the stderr to .err if there is
some error output expected, add the .xsl, .out and .err to Makefile.am
regenerate with configure, run tests to make sure it passes, and provide the
resulting patch :-)

  At least the fix should be in already,

  thanks !

Daniel

-- 
Daniel Veillard      | Red Hat Developers Tools http://developer.redhat.com/
veillard redhat com  | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | virtualization library  http://libvirt.org/



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]