fix: add explicit encoding='utf-8' to text-mode open() calls#7774
Closed
avoronov-explyt wants to merge 1 commit into
Closed
fix: add explicit encoding='utf-8' to text-mode open() calls#7774avoronov-explyt wants to merge 1 commit into
avoronov-explyt wants to merge 1 commit into
Conversation
On systems with non-UTF-8 default encoding (e.g., cp950 on Chinese Windows), open() without encoding= causes UnicodeDecodeError when reading or writing files containing non-ASCII characters. Fixes: - playwright_controller.py: already fixed on main (verified) - page_logger.py: 3 open() calls added encoding='utf-8' - chat_completion_client_recorder.py: 2 open() calls added encoding='utf-8' - docker_jupyter/_docker_jupyter.py: 1 open() call added encoding='utf-8' Added test_utf8_encoding.py to verify encoding behavior. Fixes #5566
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
On systems with non-UTF-8 default encoding (e.g., cp950 on Chinese Windows),
open()withoutencoding=causesUnicodeDecodeErrorwhen reading or writing files containing non-ASCII characters.This is reported in #5566 where
PlaywrightController.__init__fails readingpage_script.json a cp950 system.Changes
The original bug in
playwright_controller.pywas already fixed on main. This PR addresses the remainingopen()calls inautogen-extthat lack explicitencoding="utf-8":page_logger.pyopen()calls (writing hash text, HTML call tree, HTML pages)chat_completion_client_recorder.pyopen()calls (reading/writing JSON session files)docker_jupyter/_docker_jupyter.pyopen()call (writing HTML output)All changes add
encoding="utf-8"to text-modeopen()calls. Binary-mode calls ("rb","wb") are left unchanged.Testing
Added
test_utf8_encoding.pywith tests verifying:page_script.jscan be read with explicit UTF-8 encodingencoding="utf-8"in all text-modeopen()callsFixes #5566