From 35cf78b2750309072c294c553397da295bb2117b Mon Sep 17 00:00:00 2001 From: Nick Wellnhofer Date: Fri, 20 Sep 2024 00:25:00 +0200 Subject: [PATCH] variables: Evaluate globals in source order --- libxslt/variables.c | 35 ++++++++++++++--------------------- tests/general/bug-224.out | 9 +++++++++ tests/general/bug-224.xml | 8 ++++++++ tests/general/bug-224.xsl | 28 ++++++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 21 deletions(-) create mode 100644 tests/general/bug-224.out create mode 100644 tests/general/bug-224.xml create mode 100644 tests/general/bug-224.xsl diff --git a/libxslt/variables.c b/libxslt/variables.c index 09069aa3..07c17825 100644 --- a/libxslt/variables.c +++ b/libxslt/variables.c @@ -1403,28 +1403,21 @@ xsltRegisterGlobalVariable(xsltStylesheetPtr style, const xmlChar *name, elem->nameURI = xmlDictLookup(style->dict, ns_uri, -1); elem->tree = tree; tmp = style->variables; - if (tmp == NULL) { - elem->next = NULL; - style->variables = elem; - } else { - while (tmp != NULL) { - if ((elem->comp->type == XSLT_FUNC_VARIABLE) && - (tmp->comp->type == XSLT_FUNC_VARIABLE) && - (xmlStrEqual(elem->name, tmp->name)) && - ((elem->nameURI == tmp->nameURI) || - (xmlStrEqual(elem->nameURI, tmp->nameURI)))) - { - xsltTransformError(NULL, style, comp->inst, - "redefinition of global variable %s\n", elem->name); - style->errors++; - } - if (tmp->next == NULL) - break; - tmp = tmp->next; - } - elem->next = NULL; - tmp->next = elem; + while (tmp != NULL) { + if ((elem->comp->type == XSLT_FUNC_VARIABLE) && + (tmp->comp->type == XSLT_FUNC_VARIABLE) && + (xmlStrEqual(elem->name, tmp->name)) && + ((elem->nameURI == tmp->nameURI) || + (xmlStrEqual(elem->nameURI, tmp->nameURI)))) + { + xsltTransformError(NULL, style, comp->inst, + "redefinition of global variable %s\n", elem->name); + style->errors++; + } + tmp = tmp->next; } + elem->next = style->variables;; + style->variables = elem; if (value != NULL) { elem->computed = 1; elem->value = xmlXPathNewString(value); diff --git a/tests/general/bug-224.out b/tests/general/bug-224.out new file mode 100644 index 00000000..0a44197e --- /dev/null +++ b/tests/general/bug-224.out @@ -0,0 +1,9 @@ + + +id1 +id2 +id3 +id4 +id5 +id6 + diff --git a/tests/general/bug-224.xml b/tests/general/bug-224.xml new file mode 100644 index 00000000..da78efb2 --- /dev/null +++ b/tests/general/bug-224.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/tests/general/bug-224.xsl b/tests/general/bug-224.xsl new file mode 100644 index 00000000..f944c43b --- /dev/null +++ b/tests/general/bug-224.xsl @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + +