Skip to content

Fix encoding setting for non-binary IO-like objects in MockRequest#env_for#2227

Merged
jeremyevans merged 1 commit into
rack:mainfrom
jeremyevans:io-encoding-mock-request
Jul 4, 2024
Merged

Fix encoding setting for non-binary IO-like objects in MockRequest#env_for#2227
jeremyevans merged 1 commit into
rack:mainfrom
jeremyevans:io-encoding-mock-request

Conversation

@jeremyevans

Copy link
Copy Markdown
Contributor

No core class implements both encoding and set_encoding.

Classes implementing encoding:

  • Regexp
  • Symbol
  • String

Classes implementing set_encoding:

  • File
  • ARGF.class
  • IO

This code was added in 64610db. Previously, set_encoding was always called.
64610db actually broke encoding setting to binary for IO objects, but because there were no tests for the case, it wasn't caught.

I don't see a point of warning of Regexp and Symbol use, and raising for objects that support encoding but not set_encoding doesn't make sense. I'm guessing the intention was to handle IO-like objects, and then internal_encoding could be checked, but it's simpler to just call set_encoding in that case, as that was the previous behavior.

An alternative to this code would be reverting
64610db, but that is no longer backwards compatible with 3.1.0, which allows objects that do not respond to set_encoding.

Found by coverage testing.

…v_for

No core class implements both encoding and set_encoding.

Classes implementing encoding:

* Regexp
* Symbol
* String

Classes implementing set_encoding:

* File
* ARGF.class
* IO

This code was added in 64610db.
Previously, set_encoding was always called.
64610db actually broke encoding
setting to binary for IO objects, but because there were no tests
for the case, it wasn't caught.

I don't see a point of warning of Regexp and Symbol use, and
raising for objects that support encoding but not set_encoding
doesn't make sense.  I'm guessing the intention was to handle
IO-like objects, and then internal_encoding could be checked,
but it's simpler to just call set_encoding in that case, as
that was the previous behavior.

An alternative to this code would be reverting
64610db, but that is no longer
backwards compatible with 3.1.0, which allows objects that do
not respond to set_encoding.

Found by coverage testing.
@jeremyevans jeremyevans requested a review from ioquatix July 3, 2024 22:57

@ioquatix ioquatix left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM - appreciate you fixing my mess.

@jeremyevans jeremyevans merged commit ed25abc into rack:main Jul 4, 2024
@ioquatix

ioquatix commented Jul 4, 2024

Copy link
Copy Markdown
Member

Is this a bug that needs to be back ported?

@jeremyevans

Copy link
Copy Markdown
Contributor Author

Probably, as 3.0 used to set the encoding to binary and 3.1 doesn't.

@ioquatix

ioquatix commented Jul 4, 2024

Copy link
Copy Markdown
Member

Okay, so we should backport to 3.1 only?

@jeremyevans

Copy link
Copy Markdown
Contributor Author

I think so. 3.0 didn't have this issue, it always called set_encoding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants