-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
fix gets call with delimiter exactly at limit #3414
Conversation
…ter is found at pos limit If a gets call with a limit and delimiter was run on a string whose delimiter was exactly at limit, crystal would increase the perceived location of delimiter, returning a string larger by one than the supplied limit.
@@ -21,6 +21,10 @@ private class SimpleMemoryIO | |||
@pos = 0 | |||
end | |||
|
|||
def pos=(p : Int) | |||
@pos = p |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this required? If it is, you should use the setter macro.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, it doesn't seem to be required, probably a left over of some old code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
Thanks for the contribution! Looks good so far. |
@@ -94,6 +94,13 @@ describe "IO::Buffered" do | |||
io.gets('a', 3).should be_nil | |||
end | |||
|
|||
it "does gets with char and limit without off-by-one" do | |||
io = BufferedWrapper.new(MemoryIO.new("test\nabc")) | |||
io.gets('a', 5).to_s.size.should eq 5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would test what the result string is, for example:
io.gets('a', 5).should eq("test\n")
Same in the specs below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
@bmmcginty Thank you, this PR is excellent! We've made a few comments with @RX14, after fixing those things we'll merge this :-) |
I think I attached my replies to the wrong comments above, but both comments have been acted on. |
@bmmcginty Thank you!! |
If a gets call with a limit and delimiter was run on a string whose delimiter was exactly at limit,
crystal would increase the perceived location of delimiter,
returning a string larger by one than the supplied limit.
Second of the supplied test cases