fix(docs): use explicit UTF-8 encoding in redirect generation script#7811
Open
aadhar-build wants to merge 1 commit into
Open
fix(docs): use explicit UTF-8 encoding in redirect generation script#7811aadhar-build wants to merge 1 commit into
aadhar-build wants to merge 1 commit into
Conversation
The redirects.py script read and wrote files without specifying an encoding, which could cause UnicodeDecodeError or UnicodeEncodeError on Windows systems where the default locale is not UTF-8. Added encoding=\"utf-8\" to all three open() calls. Fixes microsoft#7749
avinashkamat48
left a comment
There was a problem hiding this comment.
The explicit encoding updates look good, but HTML_REDIRECT_TEMPLATE is still read at import time. If this script is imported from tooling before sys.argv/working paths are ready, any file-read error still happens during import rather than during main(). Could you move the template read into main() or generate_redirect() so importing the module stays side-effect free?
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.
Summary
python/docs/redirects/redirects.pycallsopen()three times without specifyingencoding. On Windows systems where the default locale is not UTF-8 (e.g.cp1252), this causesUnicodeDecodeErrorwhen processing files that contain UTF-8 characters.Changed: Added
encoding="utf-8"to all threeopen()calls in the file.Related issue
Closes #7749
Testing
No logic changes — this is an encoding portability fix. Works on Linux/macOS (where UTF-8 is the default) and prevents
UnicodeDecodeErroron Windows with non-UTF-8 locales.