jsonpath 1.1.2 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ab3e08744fe7f8ba3b64670fee8f75a0fa4c9b339de8257f64cdc7ea24f26965
4
- data.tar.gz: 447ce47a7c5df36c2fa290da5aafc77304d5e8db9318cfcac2b97dd9ae8c9c8c
3
+ metadata.gz: 89da09f37794d1cf177f887ea0a6c7d0da21d7106f8fd92d74d0615148feca02
4
+ data.tar.gz: 116f72d5493e540e5fde487dac9e57c3ff7f4c5122b66997a09eea899cda59a7
5
5
  SHA512:
6
- metadata.gz: 5b458262f098ceea595a91a981136141d0ed3f7ef9782d8a205f619be1bb60a7234af11229527ed9fc9ef3baafec323ad33850d87b4dc389ac482c14bb4aa05f
7
- data.tar.gz: d1756aa04d5e07de855439aa0a4895078ab5c3c2c90c4c9ec755ba1da2ffb3fe11e59d1819e03f6a82e8670fd810b1c895da150a9d24176ddf4a86a54705fcbf
6
+ metadata.gz: 25d571cacbb85435c838c25b5d3c9cd8d6d1c11b743927531af80cdfe45d4670e6e37b21030608cf2b2ff4c04c78033caeb492ceb76db24e5b35d9a514b9e669
7
+ data.tar.gz: 1b0fa8cdc648f6d889f00cd751e3e03e7f32693a5897238584d0ee67e3e3542117901755393bb36e513be6addc2fd4ab3223782df005f20024763cc14e0fc350
data/README.md CHANGED
@@ -255,7 +255,7 @@ o = JsonPath.for(json).
255
255
 
256
256
  ### Fetch all paths
257
257
 
258
- To fetch all possible paths in given json, you can use `fetch_all_paths` method.
258
+ To fetch all possible paths in given json, you can use `fetch_all_path`` method.
259
259
 
260
260
  data:
261
261
 
@@ -21,9 +21,13 @@ class JsonPath
21
21
  when '*', '..', '@'
22
22
  each(context, key, pos + 1, &blk)
23
23
  when '$'
24
- each(context, key, pos + 1, &blk) if node == @object
24
+ if node == @object
25
+ each(context, key, pos + 1, &blk)
26
+ else
27
+ handle_wildcard(node, "['#{expr}']", context, key, pos, &blk)
28
+ end
25
29
  when /^\[(.*)\]$/
26
- handle_wildecard(node, expr, context, key, pos, &blk)
30
+ handle_wildcard(node, expr, context, key, pos, &blk)
27
31
  when /\(.*\)/
28
32
  keys = expr.gsub(/[()]/, '').split(',').map(&:strip)
29
33
  new_context = filter_context(context, keys)
@@ -51,7 +55,7 @@ class JsonPath
51
55
  end
52
56
  end
53
57
 
54
- def handle_wildecard(node, expr, _context, _key, pos, &blk)
58
+ def handle_wildcard(node, expr, _context, _key, pos, &blk)
55
59
  expr[1, expr.size - 2].split(',').each do |sub_path|
56
60
  case sub_path[0]
57
61
  when '\'', '"'
@@ -64,6 +68,7 @@ class JsonPath
64
68
  else
65
69
  next if node.is_a?(Array) && node.empty?
66
70
  next if node.nil? # when default_path_leaf_to_null is true
71
+ next if node.size.zero?
67
72
 
68
73
  array_args = sub_path.split(':')
69
74
  if array_args[0] == '*'
@@ -81,6 +86,7 @@ class JsonPath
81
86
  next unless end_idx
82
87
  next if start_idx == end_idx && start_idx >= node.size
83
88
  end
89
+
84
90
  start_idx %= node.size
85
91
  end_idx %= node.size
86
92
  step = process_function_or_literal(array_args[2], 1)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class JsonPath
4
- VERSION = '1.1.2'
4
+ VERSION = '1.1.3'
5
5
  end
data/lib/jsonpath.rb CHANGED
@@ -45,11 +45,9 @@ class JsonPath
45
45
  elsif (token = scanner.scan(/[><=] \d+/))
46
46
  @path.last << token
47
47
  elsif (token = scanner.scan(/./))
48
- begin
49
- @path.last << token
50
- rescue RuntimeError
51
- raise ArgumentError, "character '#{token}' not supported in query"
52
- end
48
+ @path.last << token
49
+ else
50
+ raise ArgumentError, "character '#{scanner.peek(1)}' not supported in query"
53
51
  end
54
52
  end
55
53
  end
@@ -1178,6 +1178,10 @@ class TestJsonpath < MiniTest::Unit::TestCase
1178
1178
  assert_raises(MultiJson::ParseError) { JsonPath.new('$.a', max_nesting: 1).on(json) }
1179
1179
  end
1180
1180
 
1181
+ def test_linefeed_in_path_error
1182
+ assert_raises(ArgumentError) { JsonPath.new("$.store\n.book") }
1183
+ end
1184
+
1181
1185
  def test_with_max_nesting_false
1182
1186
  json = {
1183
1187
  a: {
@@ -1260,4 +1264,11 @@ class TestJsonpath < MiniTest::Unit::TestCase
1260
1264
  }
1261
1265
  assert_equal ["$", "$.foo", "$.bar", "$.bar.baz", "$.bars", "$.bars[0].foo", "$.bars[0]", "$.bars[1].foo", "$.bars[1]", "$.bars[2]"], JsonPath.fetch_all_path(data)
1262
1266
  end
1267
+
1268
+
1269
+ def test_extractore_with_dollar_key
1270
+ json = {"test" => {"$" =>"success", "a" => "123"}}
1271
+ assert_equal ["success"], JsonPath.on(json, "$.test.$")
1272
+ assert_equal ["123"], JsonPath.on(json, "$.test.a")
1273
+ end
1263
1274
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsonpath
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Hull
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-04-24 00:00:00.000000000 Z
12
+ date: 2023-05-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: multi_json
@@ -159,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
159
159
  - !ruby/object:Gem::Version
160
160
  version: '0'
161
161
  requirements: []
162
- rubygems_version: 3.3.7
162
+ rubygems_version: 3.4.1
163
163
  signing_key:
164
164
  specification_version: 4
165
165
  summary: Ruby implementation of http://goessner.net/articles/JsonPath/