jsonpath 0.9.7 → 0.9.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 78e6fd3aa1c1d43001e53b13939d06e137441a52
4
- data.tar.gz: 8d92b85875c0eddbb9f7c2997b21adcee58bcded
3
+ metadata.gz: a93fe71b722f53a4e02e2ea53e98a98acb281f09
4
+ data.tar.gz: afad26b3e7d0ff73db16afe367103562fc3324f8
5
5
  SHA512:
6
- metadata.gz: 488e03a62223442af4449f9c237767e31a7f0044f228049884916bd92e283a4c5efb22c8f7e1800726dc16cf60f5c7801a5788a4b847150b7dc0794244cc41a1
7
- data.tar.gz: 4a5ab8b934507c86bb7591bf2e894eb8084818d9216bae696b094452be1b8e92f270b3b903b711f6b5a82f6903dd1a267ea868398ad21ca4d1c28a21e71ba0c4
6
+ metadata.gz: e680652eaffb4d056c69038cf3abceaebc94c37de6f987aa2e0923c65bd9c7ff3c0609ce6fcbcafa0a2406ca333318d4353bbe2920c5df4d6e13820c9f49e237
7
+ data.tar.gz: 10f6f6dd70bc861974141cb9c8eff68f3da85958ca5efc8df98679ce291bb0788c997156180b5231b37f7d36f2e9caba1bbcfb87dfcf2fb7a3b3f24d49410d29
@@ -51,10 +51,14 @@ class JsonPath
51
51
  if array_args[0] == '*'
52
52
  start_idx = 0
53
53
  end_idx = node.size - 1
54
+ elsif sub_path.count(':') == 0
55
+ start_idx = end_idx = process_function_or_literal(array_args[0], 0)
56
+ next unless start_idx
57
+ next if start_idx >= node.size
54
58
  else
55
59
  start_idx = process_function_or_literal(array_args[0], 0)
56
60
  next unless start_idx
57
- end_idx = (array_args[1] && process_function_or_literal(array_args[1], -1) || (sub_path.count(':') == 0 ? start_idx : -1))
61
+ end_idx = array_args[1] && ensure_exclusive_end_index(process_function_or_literal(array_args[1], -1)) || -1
58
62
  next unless end_idx
59
63
  next if start_idx == end_idx && start_idx >= node.size
60
64
  end
@@ -72,6 +76,12 @@ class JsonPath
72
76
  end
73
77
  end
74
78
 
79
+ def ensure_exclusive_end_index(value)
80
+ return value unless value.is_a?(Integer) && value > 0
81
+
82
+ value - 1
83
+ end
84
+
75
85
  def handle_question_mark(sub_path, node, pos, &blk)
76
86
  case node
77
87
  when Array
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class JsonPath
4
- VERSION = '0.9.7'.freeze
4
+ VERSION = '0.9.8'.freeze
5
5
  end
@@ -48,13 +48,18 @@ class TestJsonpath < MiniTest::Unit::TestCase
48
48
  end
49
49
 
50
50
  def test_recognize_array_splices
51
- assert_equal [@object['store']['book'][0], @object['store']['book'][1]], JsonPath.new('$..book[0:1:1]').on(@object)
51
+ assert_equal [@object['store']['book'][0]], JsonPath.new('$..book[0:1:1]').on(@object)
52
+ assert_equal [@object['store']['book'][0], @object['store']['book'][1]], JsonPath.new('$..book[0:2:1]').on(@object)
52
53
  assert_equal [@object['store']['book'][1], @object['store']['book'][3], @object['store']['book'][5]], JsonPath.new('$..book[1::2]').on(@object)
53
54
  assert_equal [@object['store']['book'][0], @object['store']['book'][2], @object['store']['book'][4], @object['store']['book'][6]], JsonPath.new('$..book[::2]').on(@object)
54
55
  assert_equal [@object['store']['book'][0], @object['store']['book'][2]], JsonPath.new('$..book[:-5:2]').on(@object)
55
56
  assert_equal [@object['store']['book'][5], @object['store']['book'][6]], JsonPath.new('$..book[5::]').on(@object)
56
57
  end
57
58
 
59
+ def test_slice_array_with_exclusive_end_correctly
60
+ assert_equal [@object['store']['book'][0], @object['store']['book'][1]], JsonPath.new('$..book[:2]').on(@object)
61
+ end
62
+
58
63
  def test_recognize_array_comma
59
64
  assert_equal [@object['store']['book'][0], @object['store']['book'][1]], JsonPath.new('$..book[0,1]').on(@object)
60
65
  assert_equal [@object['store']['book'][2], @object['store']['book'][6]], JsonPath.new('$..book[2,-1::]').on(@object)
@@ -722,7 +727,7 @@ class TestJsonpath < MiniTest::Unit::TestCase
722
727
  { 'alfa' => 'beta11' },
723
728
  { 'alfa' => 'beta12' }] }
724
729
  expected = { 'itemList' => [{ 'alfa' => 'beta1' }] }
725
- assert_equal expected, JsonPath.for(a.to_json).delete('$.itemList[1:11:1]').to_hash
730
+ assert_equal expected, JsonPath.for(a.to_json).delete('$.itemList[1:12:1]').to_hash
726
731
  end
727
732
 
728
733
  def test_delete_more_items_with_stepping
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: 0.9.7
4
+ version: 0.9.8
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: 2018-12-03 00:00:00.000000000 Z
12
+ date: 2018-12-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: multi_json