Skip to content

Commit

Permalink
Merge pull request #53 from joshbuddy/52_float_value
Browse files Browse the repository at this point in the history
Fix for #52
  • Loading branch information
Skarlso committed May 9, 2017
2 parents 6bec446 + 44e1d80 commit 3ed0d4b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
3 changes: 1 addition & 2 deletions lib/jsonpath/enumerable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,14 @@ def process_function_or_literal(exp, default = nil)
return Integer(exp) if exp[0] != '('
return nil unless allow_eval? && @_current_node

identifiers = /@?(\.(\w+))+/.match(exp)
identifiers = /@?((?<!\d)\.(?!\d)(\w+))+/.match(exp)
# puts JsonPath.on(@_current_node, "#{identifiers}") unless identifiers.nil? ||
# @_current_node
# .methods
# .include?(identifiers[2].to_sym)

unless identifiers.nil? ||
@_current_node.methods.include?(identifiers[2].to_sym)

exp_to_eval = exp.dup
exp_to_eval[identifiers[0]] = identifiers[0].split('.').map do |el|
el == '@' ? '@_current_node' : "['#{el}']"
Expand Down
2 changes: 1 addition & 1 deletion lib/jsonpath/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class JsonPath
VERSION = '0.7.1'.freeze
VERSION = '0.7.2'.freeze
end
4 changes: 4 additions & 0 deletions test/test_jsonpath.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ def test_and_operator_with_more_results
assert_equal [@object['store']['book'][1]], JsonPath.new("$..book[?(@['price'] < 23 && @['price'] > 9)]").on(@object)
end

def test_eval_with_floating_point
assert_equal [@object['store']['book'][1]], JsonPath.new("$..book[?(@['price'] < 23.0 && @['price'] > 9.0)]").on(@object)
end

def test_no_eval
assert_equal [], JsonPath.new('$..book[(@.length-2)]', allow_eval: false).on(@object)
end
Expand Down

0 comments on commit 3ed0d4b

Please sign in to comment.