[libxslt] Fix bug 602515



commit 1d46bcde37e5985a7568a5d1e3ce0f01e4d41001
Author: Nick Wellnhofer <wellnhofer aevum de>
Date:   Mon Nov 8 10:59:24 2010 +0100

    Fix bug 602515
    
    Pattern matching with predicates

 libxslt/pattern.c         |   17 ++++++++---------
 tests/docs/bug-171.xml    |    4 ++++
 tests/general/Makefile.am |    1 +
 tests/general/bug-171.out |    2 ++
 tests/general/bug-171.xsl |    7 +++++++
 5 files changed, 22 insertions(+), 9 deletions(-)
---
diff --git a/libxslt/pattern.c b/libxslt/pattern.c
index 58bd6ed..6161376 100644
--- a/libxslt/pattern.c
+++ b/libxslt/pattern.c
@@ -888,11 +888,10 @@ restart:
 		    (node->type == XML_ELEMENT_NODE) &&
 		    (node->parent != NULL)) {
 		    xmlNodePtr previous;
-		    int ix, nocache = 0;
+		    int nocache = 0;
 
 		    previous = (xmlNodePtr)
 			XSLT_RUNTIME_EXTRA(ctxt, sel->previousExtra, ptr);
-		    ix = XSLT_RUNTIME_EXTRA(ctxt, sel->indexExtra, ival);
 		    if ((previous != NULL) &&
 			(previous->parent == node->parent)) {
 			/*
@@ -904,7 +903,7 @@ restart:
 			while (sibling != NULL) {
 			    if (sibling == previous)
 				break;
-			    if ((previous->type == XML_ELEMENT_NODE) &&
+			    if ((sibling->type == XML_ELEMENT_NODE) &&
 				(previous->name != NULL) &&
 				(sibling->name != NULL) &&
 				(previous->name[0] == sibling->name[0]) &&
@@ -925,7 +924,7 @@ restart:
 			    while (sibling != NULL) {
 				if (sibling == previous)
 				    break;
-				if ((previous->type == XML_ELEMENT_NODE) &&
+				if ((sibling->type == XML_ELEMENT_NODE) &&
 				    (previous->name != NULL) &&
 				    (sibling->name != NULL) &&
 				    (previous->name[0] == sibling->name[0]) &&
@@ -943,7 +942,8 @@ restart:
 			    }
 			}
 			if (sibling != NULL) {
-			    pos = ix + indx;
+		            pos = XSLT_RUNTIME_EXTRA(ctxt,
+                                sel->indexExtra, ival) + indx;
 			    /*
 			     * If the node is in a Value Tree we need to
 			     * save len, but cannot cache the node!
@@ -959,7 +959,6 @@ restart:
 				        sel->indexExtra, ival) = pos;
 				}
 			    }
-			    ix = pos;
 			} else
 			    pos = 0;
 		    } else {
@@ -1020,11 +1019,10 @@ restart:
 		} else if ((sel != NULL) && (sel->op == XSLT_OP_ALL) &&
 			   (node->type == XML_ELEMENT_NODE)) {
 		    xmlNodePtr previous;
-		    int ix, nocache = 0;
+		    int nocache = 0;
 
 		    previous = (xmlNodePtr)
 			XSLT_RUNTIME_EXTRA(ctxt, sel->previousExtra, ptr);
-		    ix = XSLT_RUNTIME_EXTRA(ctxt, sel->indexExtra, ival);
 		    if ((previous != NULL) &&
 			(previous->parent == node->parent)) {
 			/*
@@ -1053,7 +1051,8 @@ restart:
 			    }
 			}
 			if (sibling != NULL) {
-			    pos = ix + indx;
+			    pos = XSLT_RUNTIME_EXTRA(ctxt,
+                                sel->indexExtra, ival) + indx;
 			    /*
 			     * If the node is in a Value Tree we cannot
 			     * cache it !
diff --git a/tests/docs/bug-171.xml b/tests/docs/bug-171.xml
new file mode 100644
index 0000000..658021b
--- /dev/null
+++ b/tests/docs/bug-171.xml
@@ -0,0 +1,4 @@
+<root>
+  <text>one</text>
+  <text>two</text>
+</root>
diff --git a/tests/general/Makefile.am b/tests/general/Makefile.am
index e33a6c6..7207e15 100644
--- a/tests/general/Makefile.am
+++ b/tests/general/Makefile.am
@@ -178,6 +178,7 @@ EXTRA_DIST = \
     bug-168.out bug-168.xsl \
     bug-169.out bug-169.xsl bug-169.imp \
     bug-170.out bug-170.xsl \
+    bug-171.out bug-171.xsl \
     character.out character.xsl \
     character2.out character2.xsl \
     itemschoose.out itemschoose.xsl \
diff --git a/tests/general/bug-171.out b/tests/general/bug-171.out
new file mode 100644
index 0000000..5b87d4f
--- /dev/null
+++ b/tests/general/bug-171.out
@@ -0,0 +1,2 @@
+<?xml version="1.0"?>
+two
diff --git a/tests/general/bug-171.xsl b/tests/general/bug-171.xsl
new file mode 100644
index 0000000..25a7c94
--- /dev/null
+++ b/tests/general/bug-171.xsl
@@ -0,0 +1,7 @@
+<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
+  <xsl:template match="text[2]">
+    <xsl:value-of select="."/>
+  </xsl:template>
+
+  <xsl:template match="text()"/>
+</xsl:transform>



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