Honor read overrides on IO subclasses when sniffing - #180
Closed
OskarEichler wants to merge 2 commits into
Closed
OskarEichler wants to merge 2 commits into
OskarEichler wants to merge 2 commits into
Conversation
Author
|
Added regression coverage with a StringIO subclass whose read override accepts only the length argument. The full magic_test.rb file passes: 120 tests, 631 assertions. |
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.
Summary
Respect
readoverrides onIO/StringIOsubclasses and individual instances when choosing the magic-sniffing read mode. Use the native fast path only when the actual method is owned byIOorStringIO; inherited, unmodified native readers keep it.The existing class check treats every subclass as native. A one-argument override then receives an unexpected buffer argument; an override returning short chunks bypasses the accumulation that already works for other duck-typed readers.
Reproduction
On main
731f57062adad157a6a67f724a6f724ef77339d5, the first call raisesArgumentError; the second, when run separately, returns nil. Both returnimage/gifafter this change. The same problem affectsFilesubclasses, prepended implementations and singleton overrides.Verification
Compatibility / breaking changes
No intended breaking change, MIME signature/data change, API addition, dependency or Ruby-floor change. Overrides now use the same supported-reader behavior as other non-native IO implementations. Readers inheriting the native method retain the fast path.