Fix encoding error when trying to show a diff:#898
Merged
rafaelfranca merged 1 commit intorails:mainfrom Jul 18, 2025
Merged
Conversation
- ### Problem
Copying or creating a file with UTF-8 charatacters would raise an
encoding error when:
1) There is a collision and the user wants to see a diff.
2) The application has set its `Encoding.default_internal` to a
non-nil value.
### Context
In Rails applications, the `Encoding.default_internal` is set to
UTF-8. The `Encoding.default_external` will be used to transcode
a string because the `default_internal` is not nil. So doing
this would raise a `Encoding::UndefinedConversionError`
```ruby
content = "\xE2\x80\x99".force_encoding(Encoding::ASCII_8_BIT)
File.write("my_file.rb", content)
```
f31f16d to
6b24420
Compare
skipkayhil
approved these changes
Mar 14, 2025
Member
skipkayhil
left a comment
There was a problem hiding this comment.
Love simple changes, makes sense to me 👍
bmwiedemann
pushed a commit
to bmwiedemann/openSUSE
that referenced
this pull request
Jul 24, 2025
https://build.opensuse.org/request/show/1295381 by user dancermak + dimstar_suse - 1.4.0: ## What's Changed * Lazy-load YAML for performance improvement in rails/thor#892 * Fix encoding error when displaying diffs in rails/thor#898 * Fix unsafe shell command construction (security issue) in rails/thor#897 (bsc#1246809) * Support `git difftool`-style merge tool identifiers in rails/thor#900 * Add `gsub_file!` and make `gsub_file` fail if no substitutions occur in rails/thor#877 ## Security * CVE-2025-54314: Fixed a vulnerability where user input could result in unsafe shell command execution. (bsc#1246809) ## New Contributors * @hlascelles made their first contribution in rails/thor#893 **Full Changelog**: https://github.com/rail
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.
Ref rails/rails#54733
Problem
Copying or creating a file with UTF-8 charatacters would raise an encoding conversion error when:
Encoding.default_internalto a non-nil value.Context
In Rails applications, the
Encoding.default_internalis set to UTF-8. TheEncoding.default_externalwill be used to transcode a string because thedefault_internalis not nil. So doing this would raise aEncoding::UndefinedConversionErrorIn Thor's case, the encoding of the source file will always be
ASCII_8_BITbecause we are reading the file in binary mode:thor/lib/thor/actions/file_manipulation.rb
Line 26 in 3178667