Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow seek when underlying string is frozen #121

Merged
merged 2 commits into from
Feb 21, 2025

Conversation

headius
Copy link
Contributor

@headius headius commented Feb 20, 2025

Fixes #119. Adds a test for this expectation.

seek only modifies the StringIO pos, and should work when the
underlying String is frozen.

Fixes ruby#119
@headius
Copy link
Contributor Author

headius commented Feb 20, 2025

Sorry @kou I missed this one because nothing tested seek calls with a frozen string (not MRI tests nor ruby/spec).

I add a test here and fix the JRuby issue (#119). Release is not critical, since this only blocks us upgrading JRuby master. It would be good to resolve #120 before doing the next release (I have started work in #122).

Copy link
Member

@kou kou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem!

@@ -483,6 +483,11 @@ def test_seek
f.close unless f.closed?
end

def test_seek_frozen_string
f = StringIO.new(-"1234")
assert_nothing_raised { f.seek(0) }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, we should not use assert_nothing_raised because it doesn't nothing. We should check the read behavior instead. How about the following?

Suggested change
assert_nothing_raised { f.seek(0) }
f.seek(0)
assert_equal("234", f.read)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! I modified the test to check the return value of seek.

I will modify the tests in #122 as well but maybe not until there's some feedback on the ruby-lang bug.

@headius
Copy link
Contributor Author

headius commented Feb 20, 2025

@kou Perhaps after this is merged we should expand the test to other StringIO methods that we expect to work with a frozen string, as well as a test for the ones that should error.

@kou kou merged commit 3f90fe4 into ruby:master Feb 21, 2025
48 checks passed
matzbot pushed a commit to ruby/ruby that referenced this pull request Feb 21, 2025
@kou
Copy link
Member

kou commented Feb 21, 2025

I agree with you.

headius added a commit to headius/jruby that referenced this pull request Feb 21, 2025
This updates stringio to 3.1.5, which includes all the fixes from
ruby/stringio#116 and the regression ruby/stringio#119 fixed by
ruby/stringio#121. All CRuby tests and ruby/spec specs for stringio
are now green.

Tests are from v3.1.5 of the ruby/stringio repo.
mrzasa pushed a commit to mrzasa/ruby that referenced this pull request Feb 21, 2025
@headius headius deleted the seek_frozen_string branch February 21, 2025 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

StringIO#seek should work even if String is frozen
2 participants