tag 187583 patch
forwarded 187583 http://rt.cpan.org/Public/Bug/Display.html?id=32012
thanks

On Fri, Apr 04, 2003 at 02:10:25PM +0200, Stephane Bortzmeyer wrote:
> Package: libxml-xpath-perl
> Version: 1.13-3
> Severity: normal
> 
> 
> %  xpath -e 'text/para/node()[preceding-sibling::important and 
> position()=last()]' example.xml
> Can't call method "size" on an undefined value at 
> /usr/share/perl5/XML/XPath/Parser.pm line 107.

Hi,

this happens because evaluating the 'preceding-sibling::important' condition
loses the position/context information. I'm attaching a failing testcase
and a patch that fixes the issue.

I just re-sent the same information upstream as CPAN #32012,

 http://rt.cpan.org/Public/Bug/Display.html?id=32012

Cheers,
-- 
Niko Tyni   [EMAIL PROTECTED]
diff --git a/XPath/Step.pm b/XPath/Step.pm
index cff64a3..639fb4c 100644
--- a/XPath/Step.pm
+++ b/XPath/Step.pm
@@ -130,6 +130,8 @@ sub evaluate {
     my $from = shift; # context nodeset
     
 #    warn "Step::evaluate called with ", $from->size, " length nodeset\n";
+    my $saved_context = $self->{pp}->get_context_set;
+    my $saved_pos = $self->{pp}->get_context_pos;
     
     $self->{pp}->set_context_set($from);
     
@@ -149,7 +151,8 @@ sub evaluate {
     
 #    warn "Step::evaluate initial nodeset size: ", $initial_nodeset->size, "\n";
     
-    $self->{pp}->set_context_set(undef);
+    $self->{pp}->set_context_set($saved_context);
+    $self->{pp}->set_context_pos($saved_pos);
 
     $initial_nodeset->sort;
         
diff --git a/t/32context.t b/t/32context.t
new file mode 100644
index 0000000..9f7d5e9
--- /dev/null
+++ b/t/32context.t
@@ -0,0 +1,27 @@
+use Test;
+BEGIN { plan tests => 4 }
+
+use XML::XPath;
+ok(1);
+
+my $xp = XML::XPath->new(ioref => *DATA);
+ok($xp);
+
+# Debian bug #187583, http://bugs.debian.org/187583
+# Check that evaluation doesn't lose the context information
+
+my $nodes = $xp->find("text/para/node()[position()=last() and preceding-sibling::important]");
+ok("$nodes", " has a preceding sibling.");
+
+$nodes = $xp->find("text/para/node()[preceding-sibling::important and position()=last()]");
+ok("$nodes", " has a preceding sibling.");
+
+__DATA__
+<text>
+  <para>I start the text here, I break
+the line and I go on, I <blink>twinkle</blink> and then I go on
+    again. 
+This is not a new paragraph.</para><para>This is a
+    <important>new</important> paragraph and 
+    <blink>this word</blink> has a preceding sibling.</para>
+</text>

Reply via email to