Conversation
Member
|
we don't accept ai slop |
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.
Problem
sort-simple-yamlopens files withopen(filename, 'r+'), so reads and writes use the platform's locale encoding instead of the encoding YAML mandates (UTF-8).caféis read ascafé— and if a sort is needed the mojibake is written back: silent content corruption.UnicodeDecodeError.\nto\r\non write under Windows, so sorting an LF file emits CRLF there but LF on POSIX — platform-dependent output for identical input.Change
Open the file with
encoding='utf-8', newline=''so the hook decodes the encoding YAML specifies and produces byte-identical output on every platform. (newline=''disables\n→\r\ntranslation on write;rstrip()already normalizes whatever endings were read.)A non-UTF-8 file now raises a clear
UnicodeDecodeErrorinstead of being silently mis-decoded — the file is invalid YAML anyway, since the spec requires UTF-8/16.Testing
test_non_ascii_content_roundtripwrites a UTF-8 file with multi-byte characters and asserts the sorted output preserves them exactly. On the repo's Windows CI job the previous code would fail this (cp1252 decode +\r\nwrite).pytest tests/— 414 passed, 4 xfailed.