Skip to content

Bad path encoding#38

Merged
ondratu merged 2 commits into
masterfrom
bad_path_encoding
Jan 7, 2026
Merged

Bad path encoding#38
ondratu merged 2 commits into
masterfrom
bad_path_encoding

Conversation

@ondratu
Copy link
Copy Markdown
Contributor

@ondratu ondratu commented Jan 7, 2026

No description provided.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a bug where invalid PATH_INFO encoding could cause a KeyError: 'args' in the internal server error handler, and improves error handling for Unicode decode/encode errors in request paths.

Key changes:

  • Added proper exception handling in the Request.path property to catch and report Unicode encoding errors with HTTP 400 Bad Request
  • Fixed missing "args" key in the internal_server_error handler dictionary that caused KeyError exceptions
  • Enhanced bad_request error handler to safely handle cases where req.path cannot be parsed

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
poorwsgi/request.py Wraps path property encoding/decoding in try-except to catch UnicodeDecodeError and UnicodeEncodeError, raising HTTPException with HTTP_BAD_REQUEST status instead
poorwsgi/results.py Adds "args" key to handler dict in internal_server_error to prevent KeyError; updates bad_request to safely access req.path with exception handling and display error details in response
tests/test_request.py Adds test case to verify that bad PATH_INFO encoding triggers a 400 Bad Request response with appropriate error message
tests/test_application_error.py Adds test to verify that UnicodeDecodeError propagates correctly without being converted to KeyError (regression test for the args field fix)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/test_application_error.py Outdated
Comment thread poorwsgi/results.py
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@ondratu ondratu merged commit 4dc58bd into master Jan 7, 2026
5 checks passed
@ondratu ondratu deleted the bad_path_encoding branch January 7, 2026 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants