From b15742b21a728524ee27b9b56ef038d0a3390ecb Mon Sep 17 00:00:00 2001 From: Gergely Brautigam Date: Thu, 18 May 2017 06:45:20 +0200 Subject: [PATCH 1/9] Working on replacing eval with send. --- lib/jsonpath/enumerable.rb | 12 ++++++------ test/test_jsonpath.rb | 9 +++++++-- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/jsonpath/enumerable.rb b/lib/jsonpath/enumerable.rb index 7a1f490..204fad0 100644 --- a/lib/jsonpath/enumerable.rb +++ b/lib/jsonpath/enumerable.rb @@ -80,6 +80,8 @@ def handle_question_mark(sub_path, node, pos, &blk) when Array node.size.times do |index| @_current_node = node[index] + # exps = sub_path[1, sub_path.size - 1] + # if @_current_node.send("[#{exps.gsub(/@/, '@_current_node')}]") if process_function_or_literal(sub_path[1, sub_path.size - 1]) each(@_current_node, nil, pos + 1, &blk) end @@ -116,11 +118,6 @@ def process_function_or_literal(exp, default = nil) return nil unless allow_eval? && @_current_node identifiers = /@?((? 9 rescue false end diff --git a/test/test_jsonpath.rb b/test/test_jsonpath.rb index 7f9ad0c..0203218 100644 --- a/test/test_jsonpath.rb +++ b/test/test_jsonpath.rb @@ -109,7 +109,7 @@ def test_use_first end def test_counting - assert_equal 54, JsonPath.new('$..*').on(@object).to_a.size + assert_equal 57, JsonPath.new('$..*').on(@object).to_a.size end def test_space_in_path @@ -255,6 +255,10 @@ def test_support_underscore_in_member_names JsonPath.new("$.store._links").on(@object) end + def test_filter_support_include + #assert_equal true, JsonPath.new("$.store.book[(@.tags == 'asdf3')]").on(@object) + assert_equal true, JsonPath.new("$.store.book..tags[?(@ == 'asdf')]").on(@object) + end def example_object { 'store' => { @@ -262,7 +266,8 @@ def example_object { 'category' => 'reference', 'author' => 'Nigel Rees', 'title' => 'Sayings of the Century', - 'price' => 9 }, + 'price' => 9, + 'tags' => ['asdf', 'asdf2']}, { 'category' => 'fiction', 'author' => 'Evelyn Waugh', 'title' => 'Sword of Honour', From 5749b7b181b3346cb918aa85400dd3fbd769268a Mon Sep 17 00:00:00 2001 From: Gergely Brautigam Date: Tue, 23 May 2017 13:09:32 +0200 Subject: [PATCH 2/9] Removed the need for eval. --- lib/jsonpath.rb | 1 + lib/jsonpath/enumerable.rb | 12 ++++++---- lib/jsonpath/parser.rb | 47 ++++++++++++++++++++++++++++++++++++++ test/test_jsonpath.rb | 32 ++++++++++++++------------ 4 files changed, 74 insertions(+), 18 deletions(-) create mode 100644 lib/jsonpath/parser.rb diff --git a/lib/jsonpath.rb b/lib/jsonpath.rb index 9166b63..d25c2e8 100644 --- a/lib/jsonpath.rb +++ b/lib/jsonpath.rb @@ -3,6 +3,7 @@ require 'jsonpath/proxy' require 'jsonpath/enumerable' require 'jsonpath/version' +require 'jsonpath/parser' # JsonPath: initializes the class with a given JsonPath and parses that path # into a token array. diff --git a/lib/jsonpath/enumerable.rb b/lib/jsonpath/enumerable.rb index 204fad0..972039f 100644 --- a/lib/jsonpath/enumerable.rb +++ b/lib/jsonpath/enumerable.rb @@ -140,10 +140,14 @@ def process_function_or_literal(exp, default = nil) # node, but it's only in several nodes I wrapped this eval into rescue # returning false when error, but this eval should be refactored. begin - # instance_eval(exp.gsub(/@/, '@_current_node')) - puts "WHAAAAAAAAT" - p exp - @_current_node['price'] < 23 && @_current_node['price'] > 9 + JsonPath::Parser.new(@_current_node).parse(exp) + # proc do + # $SAFE = 1 + # instance_eval(exp) + # end.call + # puts "WHAAAAAAAAT" + # p exp + # @_current_node['price'] < 23 && @_current_node['price'] > 9 rescue false end diff --git a/lib/jsonpath/parser.rb b/lib/jsonpath/parser.rb new file mode 100644 index 0000000..aa17065 --- /dev/null +++ b/lib/jsonpath/parser.rb @@ -0,0 +1,47 @@ +require 'strscan' + +class JsonPath + # Parser parses and evaluates an expression passed to @_current_node. + class Parser + def initialize(node) + @_current_node = node + end + + def parse(exp) + exp = exp.gsub(/@/, '').gsub(/[\(\)]/, '') + scanner = StringScanner.new(exp) + until scanner.eos? + if scanner.scan(/\./) + sym = scanner.scan(/\w+/) + op = scanner.scan(/./) + num = scanner.scan(/\d+/) + return @_current_node.send(sym.to_sym).send(op.to_sym, num.to_i) + end + if t = scanner.scan(/\['\w+'\]/) + element = t + elsif t = scanner.scan(/\s+[<>=][<>=]?\s+?/) + operator = t + elsif t = scanner.scan(/(\d+)?[.,]?(\d+)?/) + operand = t + elsif t = scanner.scan(/.*/) + raise 'Could not process symbol.' + end + end + element = element.gsub(/\[|\]|'|\s+/, '') if element + return false unless @_current_node[element] + return true if operator.nil? && @_current_node[element] + case operator.strip + when '<' + @_current_node[element] < operand.strip.to_i + when '>' + @_current_node[element] > operand.strip.to_i + when '>=' + @_current_node[element] >= operand.strip.to_i + when '<=' + @_current_node[element] <= operand.strip.to_i + when '==' + @_current_node[element] == operand.strip.to_i + end + end + end +end diff --git a/test/test_jsonpath.rb b/test/test_jsonpath.rb index 0203218..c6f1efd 100644 --- a/test/test_jsonpath.rb +++ b/test/test_jsonpath.rb @@ -64,20 +64,24 @@ def test_recognize_filters assert_equal [@object['store']['book'][3]], JsonPath.new("$..book[?(@['price'] > 20)]").on(@object) end - def test_or_operator - assert_equal [@object['store']['book'][1], @object['store']['book'][3]], JsonPath.new("$..book[?(@['price'] == 13 || @['price'] == 23)]").on(@object) - end + # def test_or_operator + # assert_equal [@object['store']['book'][1], @object['store']['book'][3]], JsonPath.new("$..book[?(@['price'] == 13 || @['price'] == 23)]").on(@object) + # end - def test_and_operator - assert_equal [], JsonPath.new("$..book[?(@['price'] == 13 && @['price'] == 23)]").on(@object) - end + # def test_and_operator + # assert_equal [], JsonPath.new("$..book[?(@['price'] == 13 && @['price'] == 23)]").on(@object) + # end - 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_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_eval_with_floating_point - assert_equal [@object['store']['book'][1]], JsonPath.new("$..book[?(@['price'] < 23.0 && @['price'] > 9.0)]").on(@object) + assert_equal [@object['store']['book'][1]], JsonPath.new("$..book[?(@['price'] == 13.0)]").on(@object) end def test_no_eval @@ -255,10 +259,10 @@ def test_support_underscore_in_member_names JsonPath.new("$.store._links").on(@object) end - def test_filter_support_include - #assert_equal true, JsonPath.new("$.store.book[(@.tags == 'asdf3')]").on(@object) - assert_equal true, JsonPath.new("$.store.book..tags[?(@ == 'asdf')]").on(@object) - end + # def test_filter_support_include + # #assert_equal true, JsonPath.new("$.store.book[(@.tags == 'asdf3')]").on(@object) + # assert_equal true, JsonPath.new("$.store.book..tags[?(@ == 'asdf')]").on(@object) + # end def example_object { 'store' => { From b5ea17f215091a9341f365f869fbea384b7d2e5b Mon Sep 17 00:00:00 2001 From: Gergely Brautigam Date: Tue, 23 May 2017 13:17:28 +0200 Subject: [PATCH 3/9] Added one more operation. Now on to removing the identifiers. --- lib/jsonpath/parser.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/jsonpath/parser.rb b/lib/jsonpath/parser.rb index aa17065..e78c02f 100644 --- a/lib/jsonpath/parser.rb +++ b/lib/jsonpath/parser.rb @@ -41,6 +41,8 @@ def parse(exp) @_current_node[element] <= operand.strip.to_i when '==' @_current_node[element] == operand.strip.to_i + when '!=' + @_current_node[element] != operand.strip.to_i end end end From 1b9f2d2848461b1b4aab535b70b7c21f98f4073b Mon Sep 17 00:00:00 2001 From: Gergely Brautigam Date: Wed, 24 May 2017 07:02:33 +0200 Subject: [PATCH 4/9] Working on it --- lib/jsonpath/enumerable.rb | 21 ++++---------------- lib/jsonpath/parser.rb | 39 +++++++++++++++++++++----------------- 2 files changed, 26 insertions(+), 34 deletions(-) diff --git a/lib/jsonpath/enumerable.rb b/lib/jsonpath/enumerable.rb index 972039f..8b22a1d 100644 --- a/lib/jsonpath/enumerable.rb +++ b/lib/jsonpath/enumerable.rb @@ -122,32 +122,19 @@ def process_function_or_literal(exp, default = 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}']" + el == '@' ? '@' : "['#{el}']" end.join - + p exp_to_eval begin - return instance_eval(exp_to_eval) + return JsonPath::Parser.new(@_current_node).parse(exp_to_eval) + # return instance_eval(exp_to_eval) # if eval failed because of bad arguments or missing methods rescue StandardError return default end end - - # otherwise eval as is - # TODO: this eval is wrong, because hash accessor could be nil and nil - # cannot be compared with anything, for instance, - # @a_current_node['price'] - we can't be sure that 'price' are in every - # node, but it's only in several nodes I wrapped this eval into rescue - # returning false when error, but this eval should be refactored. begin JsonPath::Parser.new(@_current_node).parse(exp) - # proc do - # $SAFE = 1 - # instance_eval(exp) - # end.call - # puts "WHAAAAAAAAT" - # p exp - # @_current_node['price'] < 23 && @_current_node['price'] > 9 rescue false end diff --git a/lib/jsonpath/parser.rb b/lib/jsonpath/parser.rb index e78c02f..08a0d22 100644 --- a/lib/jsonpath/parser.rb +++ b/lib/jsonpath/parser.rb @@ -9,7 +9,9 @@ def initialize(node) def parse(exp) exp = exp.gsub(/@/, '').gsub(/[\(\)]/, '') + p exp scanner = StringScanner.new(exp) + elements = [] until scanner.eos? if scanner.scan(/\./) sym = scanner.scan(/\w+/) @@ -17,8 +19,9 @@ def parse(exp) num = scanner.scan(/\d+/) return @_current_node.send(sym.to_sym).send(op.to_sym, num.to_i) end - if t = scanner.scan(/\['\w+'\]/) - element = t + if t = scanner.scan(/\['\w+'\]+/) + puts "t: #{t}" + element << t elsif t = scanner.scan(/\s+[<>=][<>=]?\s+?/) operator = t elsif t = scanner.scan(/(\d+)?[.,]?(\d+)?/) @@ -27,23 +30,25 @@ def parse(exp) raise 'Could not process symbol.' end end + puts "Element: #{sym}" element = element.gsub(/\[|\]|'|\s+/, '') if element return false unless @_current_node[element] - return true if operator.nil? && @_current_node[element] - case operator.strip - when '<' - @_current_node[element] < operand.strip.to_i - when '>' - @_current_node[element] > operand.strip.to_i - when '>=' - @_current_node[element] >= operand.strip.to_i - when '<=' - @_current_node[element] <= operand.strip.to_i - when '==' - @_current_node[element] == operand.strip.to_i - when '!=' - @_current_node[element] != operand.strip.to_i - end + return true if operator.nil? && @_current_node.dig(element) + @_current_node.dig(element).send(operator.strip, operand.strip.to_i) + # case operator.strip + # when '<' + # @_current_node[element] < operand.strip.to_i + # when '>' + # @_current_node[element] > operand.strip.to_i + # when '>=' + # @_current_node[element] >= operand.strip.to_i + # when '<=' + # @_current_node[element] <= operand.strip.to_i + # when '==' + # @_current_node[element] == operand.strip.to_i + # when '!=' + # @_current_node[element] != operand.strip.to_i + # end end end end From 49797510f4b2142f361ffeb04972d489b80b972d Mon Sep 17 00:00:00 2001 From: Gergely Brautigam Date: Wed, 24 May 2017 11:26:01 +0200 Subject: [PATCH 5/9] Completely eliminated the use of Eval. --- lib/jsonpath/enumerable.rb | 3 --- lib/jsonpath/parser.rb | 31 +++++++------------------------ 2 files changed, 7 insertions(+), 27 deletions(-) diff --git a/lib/jsonpath/enumerable.rb b/lib/jsonpath/enumerable.rb index 8b22a1d..94c5ef7 100644 --- a/lib/jsonpath/enumerable.rb +++ b/lib/jsonpath/enumerable.rb @@ -124,11 +124,8 @@ def process_function_or_literal(exp, default = nil) exp_to_eval[identifiers[0]] = identifiers[0].split('.').map do |el| el == '@' ? '@' : "['#{el}']" end.join - p exp_to_eval begin return JsonPath::Parser.new(@_current_node).parse(exp_to_eval) - # return instance_eval(exp_to_eval) - # if eval failed because of bad arguments or missing methods rescue StandardError return default end diff --git a/lib/jsonpath/parser.rb b/lib/jsonpath/parser.rb index 08a0d22..e8b5973 100644 --- a/lib/jsonpath/parser.rb +++ b/lib/jsonpath/parser.rb @@ -9,7 +9,6 @@ def initialize(node) def parse(exp) exp = exp.gsub(/@/, '').gsub(/[\(\)]/, '') - p exp scanner = StringScanner.new(exp) elements = [] until scanner.eos? @@ -20,35 +19,19 @@ def parse(exp) return @_current_node.send(sym.to_sym).send(op.to_sym, num.to_i) end if t = scanner.scan(/\['\w+'\]+/) - puts "t: #{t}" - element << t + elements << t.gsub(/\[|\]|'|\s+/, '') elsif t = scanner.scan(/\s+[<>=][<>=]?\s+?/) operator = t - elsif t = scanner.scan(/(\d+)?[.,]?(\d+)?/) - operand = t + elsif t = scanner.scan(/'?(\w+)?[.,]?(\w+)?'?/) + operand = t.delete("'").strip elsif t = scanner.scan(/.*/) raise 'Could not process symbol.' end end - puts "Element: #{sym}" - element = element.gsub(/\[|\]|'|\s+/, '') if element - return false unless @_current_node[element] - return true if operator.nil? && @_current_node.dig(element) - @_current_node.dig(element).send(operator.strip, operand.strip.to_i) - # case operator.strip - # when '<' - # @_current_node[element] < operand.strip.to_i - # when '>' - # @_current_node[element] > operand.strip.to_i - # when '>=' - # @_current_node[element] >= operand.strip.to_i - # when '<=' - # @_current_node[element] <= operand.strip.to_i - # when '==' - # @_current_node[element] == operand.strip.to_i - # when '!=' - # @_current_node[element] != operand.strip.to_i - # end + return false unless @_current_node.dig(*elements) + return true if operator.nil? && @_current_node.dig(*elements) + operand = operand.to_f if operand.to_i.to_s == operand || operand.to_f.to_s == operand + @_current_node.dig(*elements).send(operator.strip, operand) end end end From e64eddb08b58d189e92bfe5f13c9db0e0d528df3 Mon Sep 17 00:00:00 2001 From: Gergely Brautigam Date: Wed, 24 May 2017 11:30:20 +0200 Subject: [PATCH 6/9] Removed begin rescue. --- lib/jsonpath/enumerable.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/jsonpath/enumerable.rb b/lib/jsonpath/enumerable.rb index 94c5ef7..49eb207 100644 --- a/lib/jsonpath/enumerable.rb +++ b/lib/jsonpath/enumerable.rb @@ -130,11 +130,7 @@ def process_function_or_literal(exp, default = nil) return default end end - begin - JsonPath::Parser.new(@_current_node).parse(exp) - rescue - false - end + JsonPath::Parser.new(@_current_node).parse(exp) end end end From 575902490deed70b42f92d67b24fedff677ca76f Mon Sep 17 00:00:00 2001 From: Gergely Brautigam Date: Thu, 25 May 2017 06:43:24 +0200 Subject: [PATCH 7/9] Added dig --- lib/jsonpath/parser.rb | 17 ++++++++++++++--- lib/jsonpath/version.rb | 2 +- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/jsonpath/parser.rb b/lib/jsonpath/parser.rb index e8b5973..1db7e0a 100644 --- a/lib/jsonpath/parser.rb +++ b/lib/jsonpath/parser.rb @@ -28,10 +28,21 @@ def parse(exp) raise 'Could not process symbol.' end end - return false unless @_current_node.dig(*elements) - return true if operator.nil? && @_current_node.dig(*elements) + el = dig(elements, @_current_node) + return false unless el + return true if operator.nil? && el operand = operand.to_f if operand.to_i.to_s == operand || operand.to_f.to_s == operand - @_current_node.dig(*elements).send(operator.strip, operand) + el.send(operator.strip, operand) + end + + private + + # @TODO: Remove this once JsonPath no longer supports ruby versions below 2.3. + def dig(keys, hash) + return nil unless hash.key?(keys.first) + return hash.fetch(keys.first) if keys.size == 1 + prev = keys.shift + dig(keys, hash.fetch(prev)) end end end diff --git a/lib/jsonpath/version.rb b/lib/jsonpath/version.rb index cac7361..848d18e 100644 --- a/lib/jsonpath/version.rb +++ b/lib/jsonpath/version.rb @@ -1,3 +1,3 @@ class JsonPath - VERSION = '0.7.2'.freeze + VERSION = '0.8.2'.freeze end From be4951ffaea095dbd55c84ea56f80ab590f29112 Mon Sep 17 00:00:00 2001 From: Gergely Brautigam Date: Thu, 25 May 2017 09:22:43 +0200 Subject: [PATCH 8/9] Removed eval. --- README.md | 2 -- lib/jsonpath/enumerable.rb | 14 +------------- test/test_jsonpath.rb | 4 ---- 3 files changed, 1 insertion(+), 19 deletions(-) diff --git a/README.md b/README.md index c052ad2..b4729b0 100644 --- a/README.md +++ b/README.md @@ -103,8 +103,6 @@ enum.any?{ |c| c == 'red' } # => true ``` -You can optionally prevent eval from being called on sub-expressions by passing in :allow_eval => false to the constructor. - ### More examples For more usage examples and variations on paths, please visit the tests. There are some more complex ones as well. diff --git a/lib/jsonpath/enumerable.rb b/lib/jsonpath/enumerable.rb index 49eb207..7a1bd80 100644 --- a/lib/jsonpath/enumerable.rb +++ b/lib/jsonpath/enumerable.rb @@ -1,19 +1,12 @@ class JsonPath class Enumerable include ::Enumerable - attr_reader :allow_eval - alias_method :allow_eval?, :allow_eval def initialize(path, object, mode, options = nil) @path = path.path @object = object @mode = mode @options = options - @allow_eval = if @options && @options.key?(:allow_eval) - @options[:allow_eval] - else - true - end end def each(context = @object, key = nil, pos = 0, &blk) @@ -27,10 +20,6 @@ def each(context = @object, key = nil, pos = 0, &blk) each(context, key, pos + 1, &blk) if node == @object when /^\[(.*)\]$/ handle_wildecard(node, expr, context, key, pos, &blk) - else - if pos == (@path.size - 1) && node && allow_eval? - yield_value(blk, context, key) if instance_eval("node #{@path[pos]}") - end end if pos > 0 && @path[pos - 1] == '..' || (@path[pos - 1] == '*' && @path[pos] != '..') @@ -75,7 +64,6 @@ def handle_wildecard(node, expr, context, key, pos, &blk) end def handle_question_mark(sub_path, node, pos, &blk) - raise 'Cannot use ?(...) unless eval is enabled' unless allow_eval? case node when Array node.size.times do |index| @@ -115,7 +103,7 @@ def yield_value(blk, context, key) def process_function_or_literal(exp, default = nil) return default if exp.nil? || exp.empty? return Integer(exp) if exp[0] != '(' - return nil unless allow_eval? && @_current_node + return nil unless @_current_node identifiers = /@?((? Date: Thu, 25 May 2017 18:38:53 +0200 Subject: [PATCH 9/9] Added support for && and || operations. --- lib/jsonpath/parser.rb | 20 +++++++++++++++++--- test/test_jsonpath.rb | 24 ++++++++++++------------ 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/lib/jsonpath/parser.rb b/lib/jsonpath/parser.rb index 1db7e0a..f2c826b 100644 --- a/lib/jsonpath/parser.rb +++ b/lib/jsonpath/parser.rb @@ -8,6 +8,20 @@ def initialize(node) end def parse(exp) + exps = exp.split(/(&&)|(\|\|)/) + ret = parse_exp(exps.shift) + exps.each_with_index do |item, index| + case item + when '&&' + ret &&= parse_exp(exps[index + 1]) + when '||' + ret ||= parse_exp(exps[index + 1]) + end + end + ret + end + + def parse_exp(exp) exp = exp.gsub(/@/, '').gsub(/[\(\)]/, '') scanner = StringScanner.new(exp) elements = [] @@ -22,10 +36,10 @@ def parse(exp) elements << t.gsub(/\[|\]|'|\s+/, '') elsif t = scanner.scan(/\s+[<>=][<>=]?\s+?/) operator = t - elsif t = scanner.scan(/'?(\w+)?[.,]?(\w+)?'?/) + elsif t = scanner.scan(/(\s+)?'?(\w+)?[.,]?(\w+)?'?(\s+)?/) # @TODO: At this point I should trim somewhere... operand = t.delete("'").strip elsif t = scanner.scan(/.*/) - raise 'Could not process symbol.' + raise "Could not process symbol: #{t}" end end el = dig(elements, @_current_node) @@ -37,7 +51,7 @@ def parse(exp) private - # @TODO: Remove this once JsonPath no longer supports ruby versions below 2.3. + # @TODO: Remove this once JsonPath no longer supports ruby versions below 2.3 def dig(keys, hash) return nil unless hash.key?(keys.first) return hash.fetch(keys.first) if keys.size == 1 diff --git a/test/test_jsonpath.rb b/test/test_jsonpath.rb index a4adf2e..09e717a 100644 --- a/test/test_jsonpath.rb +++ b/test/test_jsonpath.rb @@ -64,21 +64,21 @@ def test_recognize_filters assert_equal [@object['store']['book'][3]], JsonPath.new("$..book[?(@['price'] > 20)]").on(@object) end - # def test_or_operator - # assert_equal [@object['store']['book'][1], @object['store']['book'][3]], JsonPath.new("$..book[?(@['price'] == 13 || @['price'] == 23)]").on(@object) - # end + def test_or_operator + assert_equal [@object['store']['book'][1], @object['store']['book'][3]], JsonPath.new("$..book[?(@['price'] == 13 || @['price'] == 23)]").on(@object) + end - # def test_and_operator - # assert_equal [], JsonPath.new("$..book[?(@['price'] == 13 && @['price'] == 23)]").on(@object) - # end + def test_and_operator + assert_equal [], JsonPath.new("$..book[?(@['price'] == 13 && @['price'] == 23)]").on(@object) + end - # 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_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_eval_with_floating_point + assert_equal [@object['store']['book'][1]], JsonPath.new("$..book[?(@['price'] < 23.0 && @['price'] > 9.0)]").on(@object) + end def test_eval_with_floating_point assert_equal [@object['store']['book'][1]], JsonPath.new("$..book[?(@['price'] == 13.0)]").on(@object)