From 04ba69317ea060314581fd1f838b91a20042e424 Mon Sep 17 00:00:00 2001 From: naktak Date: Sat, 25 Jan 2025 08:23:43 +0900 Subject: [PATCH 1/2] Add test that fails with version '1.1.5' --- test/test_jsonpath.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/test_jsonpath.rb b/test/test_jsonpath.rb index 80fa0bb..afc2016 100644 --- a/test/test_jsonpath.rb +++ b/test/test_jsonpath.rb @@ -260,6 +260,10 @@ def test_join assert_equal JsonPath.new('$.store.book..author').on(@object), JsonPath.new('$.store').join('book..author').on(@object) end + def test_gsub_with_nokey + assert_equal @object2, JsonPath.for(@object).gsub('$..*[?(@.category=="fiction")]') { |v| v }.to_hash + end + def test_gsub @object2['store']['bicycle']['price'] += 10 @object2['store']['book'][0]['price'] += 10 From 63469a071a38aa1fc1218e04617bd41cbb0baf21 Mon Sep 17 00:00:00 2001 From: naktak Date: Sat, 25 Jan 2025 08:25:41 +0900 Subject: [PATCH 2/2] Fix bug in gsub with nokey --- lib/jsonpath/enumerable.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jsonpath/enumerable.rb b/lib/jsonpath/enumerable.rb index 29660ab..a29e1e1 100644 --- a/lib/jsonpath/enumerable.rb +++ b/lib/jsonpath/enumerable.rb @@ -144,7 +144,7 @@ def yield_value(blk, context, key) if key context[key] = blk.call(context[key]) else - context.replace(blk.call(context[key])) + context.replace(blk.call(context)) end end end