Skip to content

CreateFile#identical? fixed for files containing multi-byte UTF-8 codepoints #786

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 11, 2023

Conversation

tomclose
Copy link
Contributor

🌈

Currently if you regenerate a file that contains a multi-byte UTF-8 codepoint (such as €) the file will falsely be identified as having changed. This PR adds a test to the create_file_spec to identify the problem, and then fixes the problem.

The change is the same as in #656, but that PR seems to have languished unmerged for just over 3yrs. I'm hoping the testing approach in the PR will address the previous objections so that the change can be merged.

tomclose added 2 commits May 18, 2022 15:49

Partially verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
We cannot verify signatures from co-authors, and some of the co-authors attributed to this commit require their commits to be signed.
Copy link

@dorner dorner left a comment

Choose a reason for hiding this comment

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

Added one comment. Otherwise I like this!

@@ -43,7 +43,7 @@ def initialize(base, destination, data, config = {})
# Boolean:: true if it is identical, false otherwise.
#
def identical?
exists? && File.binread(destination) == render
exists? && File.binread(destination) == String.new(render).force_encoding("ASCII-8BIT")
Copy link

Choose a reason for hiding this comment

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

I'd add a comment here indicating that binread defaults to this encoding to explain why this works.

@rafaelfranca rafaelfranca merged commit 2824cd4 into rails:main May 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants