From 202f74a8eb8dcbaee91b98b5d44566f2cae42195 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Tue, 19 Aug 2014 19:56:41 +0200 Subject: [PATCH] on_call_last() should return an index, not a node. --- lib/oga/xpath/evaluator.rb | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/lib/oga/xpath/evaluator.rb b/lib/oga/xpath/evaluator.rb index 73d234c..9372536 100644 --- a/lib/oga/xpath/evaluator.rb +++ b/lib/oga/xpath/evaluator.rb @@ -549,18 +549,15 @@ module Oga end ## - # Processes the `last()` function call. This function call returns a node - # set containing the last node of the context set. + # Processes the `last()` function call. This function call returns the + # index of the last node in the current set. # # @param [Oga::XML::NodeSet] context - # @return [Oga::XML::NodeSet] + # @return [Float] # def on_call_last(context) - if context.empty? - return context - else - return XML::NodeSet.new([context.last]) - end + # XPath uses indexes 1 to N instead of 0 to N. + return context.length.to_f end ##