Repository navigation
Skip leading newlines before applying the limit in paragraph mode gets - #230
Open
Shaisolaris wants to merge 1 commit into
Open
Shaisolaris wants to merge 1 commit into
Shaisolaris wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In paragraph mode with a limit,
StringIO#getscan returnnilwhile data remains. The leading-newline skip runs inside the window already cut tolimit, so when the bytes at the read position within the limit are all newlines, it reports end of data:Because of this,
each_line("", limit)andreadlines("", limit)stop early too.This change skips the leading newlines against the whole remaining string first, then applies the limit from the new start. When only newlines remain, the position is now moved past them before returning
nil, asIO#gets("")does, soeof?is true afterwards. Previouslyposstayed put. That is the only change in paragraph mode without a limit. The same change is made in the JRuby implementation.Tests:
test_gets_paragraph_with_limitandtest_gets_paragraph_only_newlinesfail on master (nilinstead of"b";pos0 instead of 3) and pass with the change.nil, found data left unread in 944 of 1216 runs on master and 0 with the change.posmove on newline-only remainders.test/stringio/test_*.rbwith the C extension locally on Ruby 3.3: no new failures. The same 3 tests that need the core assertion helpers error with and without the change in my setup.Not tested: I could not build or run the JRuby extension locally. The Java change mirrors the C one and relies on CI.