Always return a string for StringUtil#cut_at_null_byte
#19
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.
I came across this strange behavior after reading the following open issue. Here's the stack trace with some insight:
The symptom:
The
#initialize
method of the classID3Tag::Frames::V2::GenreFrame::GenreParser
expects to get a string as a parameter but it can be invoked withnil
instead.Potential problem:
This scenario can happen due to the fact that
StringUtil#cut_at_null_byte
can return a value different thanString
. You can find one instance of the issue inD3Tag::Frames::V2::TextFrame
From the point of view of the
StringUtil
interface, I expect thatcut_at_null_byte
would cut the string until the firstnull_byte
and return the first piece of the string. That happens in most of the cases but the edge case of "empty string" is still not covered.Proposed solution:
In order to fix the issue and the symptoms, we just need to make sure
#cut_at_null_byte
returns always aString
.I've added some
specs
to the methodStringUtil#cut_at_null_byte
too.Let me know if you have any questions or comments. I would be very happy to help :)
Thanks!