lib/jsonpath/enumerable.rb in jsonpath-1.1.2 vs lib/jsonpath/enumerable.rb in jsonpath-1.1.3

- old
+ new

@@ -19,13 +19,17 @@ case expr = @path[pos] when '*', '..', '@' each(context, key, pos + 1, &blk) when '$' - each(context, key, pos + 1, &blk) if node == @object + if node == @object + each(context, key, pos + 1, &blk) + else + handle_wildcard(node, "['#{expr}']", context, key, pos, &blk) + end when /^\[(.*)\]$/ - handle_wildecard(node, expr, context, key, pos, &blk) + handle_wildcard(node, expr, context, key, pos, &blk) when /\(.*\)/ keys = expr.gsub(/[()]/, '').split(',').map(&:strip) new_context = filter_context(context, keys) yield_value(blk, new_context, key) end @@ -49,11 +53,11 @@ memo << dig_as_hash(c, keys) end end end - def handle_wildecard(node, expr, _context, _key, pos, &blk) + def handle_wildcard(node, expr, _context, _key, pos, &blk) expr[1, expr.size - 2].split(',').each do |sub_path| case sub_path[0] when '\'', '"' k = sub_path[1, sub_path.size - 2] yield_if_diggable(node, k) do @@ -62,10 +66,11 @@ when '?' handle_question_mark(sub_path, node, pos, &blk) else next if node.is_a?(Array) && node.empty? next if node.nil? # when default_path_leaf_to_null is true + next if node.size.zero? array_args = sub_path.split(':') if array_args[0] == '*' start_idx = 0 end_idx = node.size - 1 @@ -79,9 +84,10 @@ end_idx = array_args[1] && ensure_exclusive_end_index(process_function_or_literal(array_args[1], -1)) || -1 next unless end_idx next if start_idx == end_idx && start_idx >= node.size end + start_idx %= node.size end_idx %= node.size step = process_function_or_literal(array_args[2], 1) next unless step