Avoid encoding errors in PING and PONG frame logging - #1766
Closed
GruffElixir wants to merge 1 commit into
Closed
GruffElixir wants to merge 1 commit into
GruffElixir wants to merge 1 commit into
Conversation
Member
|
IMO that would be a bug in the handler. It's the responsibility of the handler to decide how to deal with data that it cannot encode. |
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
Escape non-ASCII text when rendering PING and PONG payloads for log messages. These control frames can contain internally generated random bytes; if they happen to decode as Unicode, writing the log message through a non-UTF-8 handler can raise
UnicodeEncodeError. ASCII payloads and other frame representations retain their existing output.Test plan
PYTHONPATH=src python -m unittest tests.test_frames tests.test_protocol tests.test_connectionpython -m ruff format --check src/websockets/frames.py tests/test_frames.pypython -m ruff check src/websockets/frames.py tests/test_frames.pygit diff --checkFixes #1763