Repository navigation
docs: clarify json_params_matcher non-strict matching and accepted types - #837
mayureshsonawane17 wants to merge 1 commit into
Conversation
| """"""""""""""""" | ||
|
|
||
| Matching JSON encoded data can be done with ``matchers.json_params_matcher()``. | ||
| It supports JSON dictionaries, lists, and scalar values. |
There was a problem hiding this comment.
Bug: The documentation for json_params_matcher() claims support for all scalar values, but the implementation incorrectly handles falsy scalars (0, False, ""), treating them as an empty dictionary {}.
Severity: MEDIUM
Suggested Fix
The implementation of json_params_matcher() should be updated to correctly handle falsy scalar values. Instead of relying on a truthiness check like param or {}, explicitly check if the parameter is None to decide whether to default to an empty dictionary. This will ensure that falsy values like 0, False, and "" are preserved and used for matching as documented.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: README.rst#L311
Potential issue: The documentation added at `README.rst:311` states that
`matchers.json_params_matcher()` supports scalar values. However, the implementation
uses a truthiness check that causes falsy scalar values like `0`, `False`, or `""` to be
coerced into an empty dictionary `{}`. Consequently, a user attempting to match a
request body containing a falsy scalar (e.g., `json_params_matcher(0)` for a body of
`"0"`) will experience a silent match failure, as the code will compare the parsed body
(`0`) against an empty dictionary (`{}`). This behavior contradicts the documentation.
Did we get this right? 👍 / 👎 to inform future reviews.
|
Thank you for the review feedback! That is an accurate catch. The underlying issue where falsy scalar JSON primitives ( I have synchronized the documentation wording in this PR to align with the accepted parameter types while PR #836 resolves the implementation behavior. |
|
There is a lint error introduced by these changes, could we get that addressed? |
Summary
This PR improves the documentation for in by:
Test Plan