{Test} Skip email replacer if the request body is not string#31829
{Test} Skip email replacer if the request body is not string#31829
Conversation
… could be a zip file
️✔️AzureCLI-FullTest
|
️✔️AzureCLI-BreakingChangeTest
|
There was a problem hiding this comment.
Pull Request Overview
This PR enhances the email replacer in process_request to skip non-string bodies and avoid UnicodeDecodeError when processing binary payloads.
- Wraps the body replacement in a
try/exceptto catch decoding errors. - Leaves the request body unchanged if it cannot be decoded as UTF-8.
Comments suppressed due to low confidence (1)
src/azure-cli-testsdk/azure/cli/testsdk/utilities.py:226
- Add a unit test for the case where
request.bodyis binary or contains invalid UTF-8 to verify that the UnicodeDecodeError is caught and the replacement is skipped.
try:
| if request.body: | ||
| body = _byte_to_str(request.body) | ||
| request.body = self._replace_email_address(body) | ||
| try: |
There was a problem hiding this comment.
[nitpick] Consider checking isinstance(request.body, bytes) before decoding instead of using exception handling for control flow, which makes the logic clearer and avoids the cost of catching exceptions.
|
Thank you for your contribution! We will review the pull request and get back to you soon. |
|
The git hooks are available for azure-cli and azure-cli-extensions repos. They could help you run required checks before creating the PR. Please sync the latest code with latest dev branch (for azure-cli) or main branch (for azure-cli-extensions). pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>
|
Related command
Description
There could be some cases that request body is not string (for example a zip file). EmailReplacer will fail on
_byte_to_strwithUnicodeDecodeError. In such case, there's no need to replace anything so skipping EmailReplacer directlyTesting Guide
History Notes
[Component Name 1] BREAKING CHANGE:
az command a: Make some customer-facing breaking change[Component Name 2]
az command b: Add some customer-facing featureThis checklist is used to make sure that common guidelines for a pull request are followed.
The PR title and description has followed the guideline in Submitting Pull Requests.
I adhere to the Command Guidelines.
I adhere to the Error Handling Guidelines.