lib/jsonpath/parser.rb in jsonpath-0.9.1 vs lib/jsonpath/parser.rb in jsonpath-0.9.2

- old
+ new

@@ -36,13 +36,20 @@ if t = scanner.scan(/\['[a-zA-Z@&\*\/\$%\^\?_]+'\]+/) elements << t.gsub(/\[|\]|'|\s+/, '') elsif t = scanner.scan(/(\s+)?[<>=][=~]?(\s+)?/) operator = t elsif t = scanner.scan(/(\s+)?'?.*'?(\s+)?/) - operand = operator.strip == "=~" ? t.to_regexp : t.delete("'").strip + # If we encounter a node which does not contain `'` it means + # that we are dealing with a boolean type. + if t == "true" + operand = true + elsif t == "false" + operand = false + else + operand = operator.strip == "=~" ? t.to_regexp : t.delete("'").strip + end elsif t = scanner.scan(/\/\w+\//) - elsif t = scanner.scan(/.*/) raise "Could not process symbol: #{t}" end end @@ -54,11 +61,11 @@ 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) + + el.__send__(operator.strip, operand) end private # @TODO: Remove this once JsonPath no longer supports ruby versions below 2.3