Skip to content

Commit f620e7b

Browse files
committed
Fix a mistake causing negative indices on ring switches
It might fix espadrine#1 as a side-effect?
1 parent 63a6208 commit f620e7b

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

lib/json-diff/diff.rb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -311,15 +311,10 @@ def self.array_changes(pairing)
311311
while i < len
312312
ni = (i + 1) % len # next i
313313
if ring[i] != ring[ni]
314-
pairs << [ring[i], ring[ni], orig_ring[i][0], orig_ring[ni][1]]
314+
pairs << [ring_map.map(ring[i]), ring[ni], orig_ring[i][0], orig_ring[ni][1]]
315315
end
316316
ring_map.removal(ring[i])
317317
ring_map.addition(ring[ni])
318-
j = i + 1
319-
while j < len
320-
ring[j] = ring_map.map(ring[j])
321-
j += 1
322-
end
323318
i += 1
324319
end
325320
end

lib/json-diff/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module JsonDiff
2-
VERSION = '0.3.1'
2+
VERSION = '0.3.2'
33
end

spec/json-diff/diff_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,20 @@
5757
])
5858
end
5959

60+
it "should be able to diff a ring switch" do
61+
diff = JsonDiff.diff([1, 2, 3], [2, 3, 1], include_was: true)
62+
expect(diff).to eql([{"op" => "move", "from" => "/0", "path" => "/2"}])
63+
end
64+
65+
it "should be able to diff a ring switch with removals and additions" do
66+
diff = JsonDiff.diff([1, 2, 3, 4], [5, 3, 4, 2], include_was: true)
67+
expect(diff).to eql([
68+
{"op" => "remove", "path" => "/0", "was" => 1},
69+
{"op" => "move", "from" => "/0", "path" => "/2"},
70+
{"op" => "add", "path" => "/0", "value" => 5},
71+
])
72+
end
73+
6074
it "should be able to diff two arrays with mixed content" do
6175
diff = JsonDiff.diff(["laundry", 12, {'pillar' => 0}, true], [true, {'pillar' => 1}, 3, 12], include_was: true)
6276
expect(diff).to eql([

0 commit comments

Comments
 (0)