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

fix gets call with delimiter exactly at limit #3414

Merged
merged 3 commits into from
Oct 12, 2016

Conversation

bmmcginty
Copy link
Contributor

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

Verified

This commit was signed with the committer’s verified signature.
…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
Copy link
Member

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.

Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed.

@RX14
Copy link
Member

RX14 commented Oct 12, 2016

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
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@asterite
Copy link
Member

@bmmcginty Thank you, this PR is excellent! We've made a few comments with @RX14, after fixing those things we'll merge this :-)

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@bmmcginty
Copy link
Contributor Author

I think I attached my replies to the wrong comments above, but both comments have been acted on.

@asterite
Copy link
Member

@bmmcginty Thank you!!

@asterite asterite merged commit 631fdce into crystal-lang:master Oct 12, 2016
@asterite asterite added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib labels Oct 12, 2016
@asterite asterite added this to the 0.20.0 milestone Oct 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants