Add frozen_string_literal everywhere and fix string mutation with force_encoding #592
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.
This PR has two commits:
# frozen_string_literal: true
to every file. This will help with migration to ruby 3, where all literals will be frozen. This functionality was added in ruby 2.3.force_encoding
inRequest
. String#force_encoding is a mutating function, which will raise a RuntimeError if the response body is a frozen string.This is mostly causing issues for us with testing using
stub_response
in our application, since we have enabled frozen string literals.For example, the following test fails when frozen_string_literals are enabled:
httparty/spec/httparty/request_spec.rb
Lines 551 to 559 in da1b1ad
The issue also exists with this gem's tests, which you can see by running
git checkout 9c4c7a0 && bundle exec rake
.This should not be a breaking change and is being done by other gems as well (e.g. stripe/stripe-ruby#649).
@jnunemaker If you're not interested adding the frozen_string_literal comment everywhere, I'd be happy to pull out
1f29818
as a separate PR as well.