From bea7e19d57e9a1c72edd26dedc3b8c1716e3b87f Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Fri, 24 Jul 2015 00:30:20 +0200 Subject: [PATCH] Cast compiled predicate indexes to integers --- lib/oga/xpath/compiler.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/oga/xpath/compiler.rb b/lib/oga/xpath/compiler.rb index 646b7e1..d635661 100644 --- a/lib/oga/xpath/compiler.rb +++ b/lib/oga/xpath/compiler.rb @@ -211,7 +211,7 @@ module Oga # def index_predicate(test, predicate, input) int1 = literal('1') - index = on_int(predicate) + index = to_int(predicate) index_var = literal('index') inner = process(test, input) do |matched_test_node| @@ -293,7 +293,7 @@ module Oga # @param [Oga::Ruby::Node] input # @return [Oga::Ruby::Node] def on_int(ast, *) - literal(ast.children[0].to_i.to_s) + literal(ast.children[0].to_f.to_s) end # @param [AST::Node] ast @@ -382,6 +382,12 @@ module Oga literal('variables') end + # @param [AST::Node] ast + # @return [Oga::Ruby::Node] + def to_int(ast) + literal(ast.children[0].to_i.to_s) + end + # @param [AST::Node] ast # @return [TrueClass|FalseClass] def number?(ast)