From 9c256525243e745d47f1a672967dc4784e42bc45 Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Sat, 23 Jun 2001 12:24:49 +0000 Subject: [PATCH] closing bug #56517, fixed a number of problems in the patterns * libxslt/pattern.c: closing bug #56517, fixed a number of problems in the patterns compilations, priorities and debug * libxslt/transform.c: improved the template debug message * tests/docs/Makefile.am tests/general/Makefile.am tests/general/bug-39-* tests/docs/bug-39-*: added a specific regression test for #56517 Daniel --- ChangeLog | 9 +++++++++ libxslt/pattern.c | 46 +++++++++++++++++++++++++++++++--------------- libxslt/transform.c | 10 ++++++---- tests/docs/Makefile.am | 1 + tests/docs/bug-39-.xml | 3 +++ tests/general/Makefile.am | 1 + tests/general/bug-39-.out | 3 +++ tests/general/bug-39-.xsl | 34 ++++++++++++++++++++++++++++++++++ 8 files changed, 88 insertions(+), 19 deletions(-) create mode 100644 tests/docs/bug-39-.xml create mode 100644 tests/general/bug-39-.out create mode 100644 tests/general/bug-39-.xsl diff --git a/ChangeLog b/ChangeLog index 7ecd03f..64445e9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +Sat Jun 23 14:20:01 CEST 2001 Daniel Veillard + + * libxslt/pattern.c: closing bug #56517, fixed a number of + problems in the patterns compilations, priorities and debug + * libxslt/transform.c: improved the template debug message + * tests/docs/Makefile.am tests/general/Makefile.am + tests/general/bug-39-* tests/docs/bug-39-*: added a specific + regression test for #56517 + Fri Jun 22 16:17:23 CEST 2001 Daniel Veillard * libxslt/xslt.c: avoid a stupid bug when compiling with diff --git a/libxslt/pattern.c b/libxslt/pattern.c index 50ff468..bc2c214 100644 --- a/libxslt/pattern.c +++ b/libxslt/pattern.c @@ -79,6 +79,7 @@ struct _xsltStepOp { struct _xsltCompMatch { struct _xsltCompMatch *next; /* siblings in the name hash */ float priority; /* the priority */ + const xmlChar *pattern; /* the pattern */ const xmlChar *mode; /* the mode */ const xmlChar *modeURI; /* the mode URI */ xsltTemplatePtr template; /* the associated template */ @@ -145,6 +146,8 @@ xsltFreeCompMatch(xsltCompMatchPtr comp) { if (comp == NULL) return; + if (comp->pattern != NULL) + xmlFree((xmlChar *)comp->pattern); if (comp->mode != NULL) xmlFree((xmlChar *)comp->mode); if (comp->modeURI != NULL) @@ -1459,11 +1462,6 @@ xsltCompilePattern(const xmlChar *pattern, xmlDocPtr doc, xmlNodePtr node) { return(NULL); } -#ifdef WITH_XSLT_DEBUG_PATTERN - xsltGenericDebug(xsltGenericDebugContext, - "xsltCompilePattern : parsing '%s'\n", pattern); -#endif - ctxt = xsltNewParserContext(); if (ctxt == NULL) return(NULL); @@ -1494,10 +1492,17 @@ xsltCompilePattern(const xmlChar *pattern, xmlDocPtr doc, xmlNodePtr node) { ctxt->comp = element; ctxt->base = xmlStrndup(&pattern[start], end - start); + if (ctxt->base == NULL) + goto error; ctxt->cur = &(ctxt->base)[current - start]; + element->pattern = ctxt->base; + +#ifdef WITH_XSLT_DEBUG_PATTERN + xsltGenericDebug(xsltGenericDebugContext, + "xsltCompilePattern : parsing '%s'\n", + element->pattern); +#endif xsltCompileLocationPathPattern(ctxt); - if (ctxt->base) - xmlFree((xmlChar *)ctxt->base); if (ctxt->error) goto error; @@ -1514,9 +1519,11 @@ xsltCompilePattern(const xmlChar *pattern, xmlDocPtr doc, xmlNodePtr node) { (element->steps[0].value != NULL) && (element->steps[1].op == XSLT_OP_END)) { element->priority = 0; +#if 0 } else if ((element->steps[0].op == XSLT_OP_ROOT) && (element->steps[1].op == XSLT_OP_END)) { element->priority = 0; +#endif } else if ((element->steps[0].op == XSLT_OP_PI) && (element->steps[0].value != NULL) && (element->steps[1].op == XSLT_OP_END)) { @@ -1544,6 +1551,11 @@ xsltCompilePattern(const xmlChar *pattern, xmlDocPtr doc, xmlNodePtr node) { } else { element->priority = 0.5; } +#ifdef WITH_XSLT_DEBUG_PATTERN + xsltGenericDebug(xsltGenericDebugContext, + "xsltCompilePattern : parsed %s, default priority %f\n", + element->pattern, element->priority); +#endif if (pattern[end] == '|') end++; current = end; @@ -1587,24 +1599,25 @@ xsltAddTemplate(xsltStylesheetPtr style, xsltTemplatePtr cur, const xmlChar *mode, const xmlChar *modeURI) { xsltCompMatchPtr pat, list, *top = NULL, next; const xmlChar *name = NULL; + float priority; /* the priority */ if ((style == NULL) || (cur == NULL) || (cur->match == NULL)) return(-1); + priority = cur->priority; pat = xsltCompilePattern(cur->match, style->doc, cur->elem); while (pat) { next = pat->next; pat->next = NULL; + name = NULL; pat->template = cur; if (mode != NULL) pat->mode = xmlStrdup(mode); if (modeURI != NULL) pat->modeURI = xmlStrdup(modeURI); - if (cur->priority == XSLT_PAT_NO_PRIORITY) - cur->priority = pat->priority; - else - pat->priority = cur->priority; + if (priority != XSLT_PAT_NO_PRIORITY) + pat->priority = priority; /* * insert it in the hash table list corresponding to its lookup name @@ -1726,11 +1739,11 @@ xsltAddTemplate(xsltStylesheetPtr style, xsltTemplatePtr cur, if (mode) xsltGenericDebug(xsltGenericDebugContext, "added pattern : '%s' mode '%s' priority %f\n", - pat->template->match, pat->mode, pat->priority); + pat->pattern, pat->mode, pat->priority); else xsltGenericDebug(xsltGenericDebugContext, "added pattern : '%s' priority %f\n", - pat->template->match, pat->priority); + pat->pattern, pat->priority); #endif pat = next; @@ -1756,6 +1769,7 @@ xsltGetTemplate(xsltTransformContextPtr ctxt, xmlNodePtr node, xsltTemplatePtr ret = NULL; const xmlChar *name = NULL; xsltCompMatchPtr list = NULL; + float priority; if ((ctxt == NULL) || (node == NULL)) return(NULL); @@ -1767,6 +1781,7 @@ xsltGetTemplate(xsltTransformContextPtr ctxt, xmlNodePtr node, } while ((curstyle != NULL) && (curstyle != style)) { + priority = XSLT_PAT_NO_PRIORITY; /* TODO : handle IDs/keys here ! */ if (curstyle->templatesHash != NULL) { /* @@ -1813,6 +1828,7 @@ xsltGetTemplate(xsltTransformContextPtr ctxt, xmlNodePtr node, if (xsltTestCompMatch(ctxt, list, node, ctxt->mode, ctxt->modeURI)) { ret = list->template; + priority = list->priority; break; } list = list->next; @@ -1861,7 +1877,7 @@ xsltGetTemplate(xsltTransformContextPtr ctxt, xmlNodePtr node, } while ((list != NULL) && - ((ret == NULL) || (list->priority > ret->priority))) { + ((ret == NULL) || (list->priority > priority))) { if (xsltTestCompMatch(ctxt, list, node, ctxt->mode, ctxt->modeURI)) { ret = list->template; @@ -1872,7 +1888,7 @@ xsltGetTemplate(xsltTransformContextPtr ctxt, xmlNodePtr node, if (node->_private != NULL) { list = curstyle->keyMatch; while ((list != NULL) && - ((ret == NULL) || (list->priority > ret->priority))) { + ((ret == NULL) || (list->priority > priority))) { if (xsltTestCompMatch(ctxt, list, node, ctxt->mode, ctxt->modeURI)) { ret = list->template; diff --git a/libxslt/transform.c b/libxslt/transform.c index 8b24e99..b41ea59 100644 --- a/libxslt/transform.c +++ b/libxslt/transform.c @@ -890,8 +890,8 @@ xsltProcessOneNode(xsltTransformContextPtr ctxt, xmlNodePtr node) { if (node->type == XML_ATTRIBUTE_NODE) { #ifdef WITH_XSLT_DEBUG_PROCESS xsltGenericDebug(xsltGenericDebugContext, - "xsltProcessOneNode: applying template for attribute %s\n", - node->name); + "xsltProcessOneNode: applying template '%s' for attribute %s\n", + template->match, node->name); #endif templPush(ctxt, template); xsltApplyOneTemplate(ctxt, node, template->content, 1); @@ -900,10 +900,12 @@ xsltProcessOneNode(xsltTransformContextPtr ctxt, xmlNodePtr node) { #ifdef WITH_XSLT_DEBUG_PROCESS if (node->type == XML_DOCUMENT_NODE) xsltGenericDebug(xsltGenericDebugContext, - "xsltProcessOneNode: applying template for /\n"); + "xsltProcessOneNode: applying template '%s' for /\n", + template->match); else xsltGenericDebug(xsltGenericDebugContext, - "xsltProcessOneNode: applying template for %s\n", node->name); + "xsltProcessOneNode: applying template '%s' for %s\n", + template->match, node->name); #endif oldNode = ctxt->node; ctxt->node = node; diff --git a/tests/docs/Makefile.am b/tests/docs/Makefile.am index a834bde..867c61c 100644 --- a/tests/docs/Makefile.am +++ b/tests/docs/Makefile.am @@ -42,6 +42,7 @@ EXTRA_DIST = \ bug-36-.xml \ bug-37-.xml \ bug-38-.xml \ + bug-39-.xml \ character.xml \ array.xml \ items.xml diff --git a/tests/docs/bug-39-.xml b/tests/docs/bug-39-.xml new file mode 100644 index 0000000..ae743eb --- /dev/null +++ b/tests/docs/bug-39-.xml @@ -0,0 +1,3 @@ + + + diff --git a/tests/general/Makefile.am b/tests/general/Makefile.am index 3ab5c7c..c2da73d 100644 --- a/tests/general/Makefile.am +++ b/tests/general/Makefile.am @@ -44,6 +44,7 @@ EXTRA_DIST = \ bug-37-inc.out bug-37-inc.xsl \ array.out array.xsl \ bug-38-.out bug-38-.xsl \ + bug-39-.out bug-39-.xsl \ character.out character.xsl \ character2.out character2.xsl \ itemschoose.out itemschoose.xsl \ diff --git a/tests/general/bug-39-.out b/tests/general/bug-39-.out new file mode 100644 index 0000000..ba9b93e --- /dev/null +++ b/tests/general/bug-39-.out @@ -0,0 +1,3 @@ + +Matched /* or y template + diff --git a/tests/general/bug-39-.xsl b/tests/general/bug-39-.xsl new file mode 100644 index 0000000..96b8d3a --- /dev/null +++ b/tests/general/bug-39-.xsl @@ -0,0 +1,34 @@ + + + + + + + + + + + Matched x template + + + + + + + Matched /* or y template + + + + + + -- 2.7.4