-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(rename): read and write source files as UTF-8 #6761
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Fixed `reflex rename` corrupting or failing on UTF-8 source files on non-UTF-8 platform locales (e.g. Windows cp1252) by reading and writing files as UTF-8. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -97,7 +97,7 @@ def rename_imports_and_app_name(file_path: str | Path, old_name: str, new_name: | |
| new_name: The new name to use. | ||
| """ | ||
| file_path = Path(file_path) | ||
| content = file_path.read_text() | ||
| content = file_path.read_text(encoding="utf-8") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
For Useful? React with 👍 / 👎. |
||
|
|
||
| # Replace `from old_name.` or `from old_name` with `from new_name` | ||
| content = re.sub( | ||
|
|
@@ -127,7 +127,7 @@ def rename_imports_and_app_name(file_path: str | Path, old_name: str, new_name: | |
| content, | ||
| ) | ||
|
|
||
| file_path.write_text(content) | ||
| file_path.write_text(content, encoding="utf-8") | ||
|
|
||
|
|
||
| def process_directory( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the app contains valid Python source declared as
cp1252orlatin-1, a non-ASCII byte such as0xe9now raisesUnicodeDecodeError. The rename traversal passes every.pyfile here and may already have rewritten earlier files, leaving the app partially renamed; detect the source encoding and preserve it instead of always decoding as UTF-8.