Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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