From 0c677b7a1db3e204e78ac682487e8c6345c7f64b Mon Sep 17 00:00:00 2001 From: Kyrylo Silin Date: Mon, 28 Jun 2021 22:31:53 +0300 Subject: [PATCH] ring: change guard priority so that the value at index can be read Fixes #2199 (`_out_` Ring is ill-addressible) --- CHANGELOG.md | 5 +++++ lib/pry/ring.rb | 2 +- spec/ring_spec.rb | 4 +++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a3bc0eb..65ec4029 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ ### master +#### Bug fixes + +* Fixed bug where reading from the `_out_` sticky local variable could return + wrong results ([#2201](https://github.com/pry/pry/pull/2201)) + ### [v0.14.1][v0.14.1] (April 12, 2021) #### Bug fixes diff --git a/lib/pry/ring.rb b/lib/pry/ring.rb index a61d077a..653ffb59 100644 --- a/lib/pry/ring.rb +++ b/lib/pry/ring.rb @@ -56,8 +56,8 @@ class Pry # exist def [](index) @mutex.synchronize do - return @buffer[(count + index) % max_size] if index.is_a?(Integer) return @buffer[index] if count <= max_size + return @buffer[(count + index) % max_size] if index.is_a?(Integer) transpose_buffer_tail[index] end diff --git a/spec/ring_spec.rb b/spec/ring_spec.rb index 4c7efbb5..3d5572ae 100644 --- a/spec/ring_spec.rb +++ b/spec/ring_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true describe Pry::Ring do - let(:ring) { described_class.new(3) } + subject(:ring) { described_class.new(3) } describe "#<<" do it "adds elements as is when the ring is not full" do @@ -28,6 +28,8 @@ describe Pry::Ring do end context "when the ring is not full" do + subject(:ring) { described_class.new(100) } + before { ring << 1 << 2 << 3 } it "reads elements" do