lib/jsonpath/parser.rb in jsonpath-0.8.12 vs lib/jsonpath/parser.rb in jsonpath-0.9.0

- old
+ new

@@ -44,25 +44,28 @@ elsif t = scanner.scan(/.*/) raise "Could not process symbol: #{t}" end end - el = dig(elements, @_current_node) + if elements.empty? + el = @_current_node + else + el = dig(elements, @_current_node) + end return false if el.nil? return true if operator.nil? && el el = Float(el) rescue el operand = Float(operand) rescue operand operand = false if operand == 'false' && el == false - 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 hash unless hash.is_a? Hash + return nil unless hash.is_a? 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