Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Ensure that falsy response bodies are correctly handled #2454

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jaridmargolin
Copy link

Description

The title should be fairly descriptive of what is implemented. Before the PR, if a recorded request returned a body with the value of false or null, on subsequent usage, it would incorrectly be loaded as an empty string. This small patch ensures the value is accurately replayed.

Note: This was opened up against main because no next or beta branches were found.

@mastermatt
Copy link
Member

Returning an empty string is intended behavior. The native http module in Node, which Nock makes a point to mimic as close as possible, will always return a buffer. Never null or undefined. And if the buffer can be stringified by the client, that is intended/expected.

@jaridmargolin
Copy link
Author

@mastermatt There may be a misunderstanding due to my description. I have a concrete bug where nock is incorrectly changing a JSON response, where the value of that JSON is false, to an empty string when loading and replaying.

I may have oversimplified the solution due to my lack of knowledge of the internals, but with the above patch, all tests are still passing and the failing case is fixed.

@mikicho
Copy link
Contributor

mikicho commented Feb 16, 2024

@jaridmargolin IIUC and according to the types, responses must be either a string or an object. Maybe the problem is in the recorder, which saves value as a boolean?

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.

None yet

3 participants