Skip to content

Fix binary response handling with regex conditions#18

Merged
mcustiel merged 1 commit into
mcustiel:masterfrom
manofearth:binary_body_with_regex_condition_fix
Dec 27, 2024
Merged

Fix binary response handling with regex conditions#18
mcustiel merged 1 commit into
mcustiel:masterfrom
manofearth:binary_body_with_regex_condition_fix

Conversation

@manofearth
Copy link
Copy Markdown
Contributor

When using regex conditions (for URL or body) with binary response body, the content was incorrectly returned as a string with 'phiremock.base64:' prefix instead of actual binary data.

This PR fixes the issue by:

  • Adding a check for BinaryBody instance in RegexResponseStrategy
  • Bypassing regex replacement logic for binary responses since substitutions from regex capture groups are not applicable for binary data
  • Adding a test case to verify binary response works correctly with regex URL matching

The change ensures binary responses (like images) are properly handled regardless of whether regex conditions are used in the expectation.

Copy link
Copy Markdown
Owner

@mcustiel mcustiel left a comment

Choose a reason for hiding this comment

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

Nice catch. And thank you for taking care and covering it with tests ❤️

@mcustiel mcustiel merged commit 894a13a into mcustiel:master Dec 27, 2024
@manofearth manofearth deleted the binary_body_with_regex_condition_fix branch May 15, 2025 06:18
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