Bad path encoding#38
Merged
Merged
Conversation
1ec19a9 to
3637f5f
Compare
Contributor
There was a problem hiding this comment.
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.pathproperty 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.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.
No description provided.