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

Do not send undefined values in form data #145

Merged
merged 2 commits into from
Dec 28, 2021

Conversation

KnorpelSenf
Copy link
Member

Closes #144

@KnorpelSenf KnorpelSenf added the fix Fixes a bug label Dec 28, 2021
@@ -113,6 +113,7 @@ async function* payloadToMultipartItr(
const separator = enc.encode(`\r\n--${boundary}\r\n`);
let first = true;
for (const [key, value] of Object.entries(payload)) {
if (value == null) continue;
Copy link
Member

Choose a reason for hiding this comment

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

Without trying this out… parse_mode: undefined shouldnt match null?

Maybe I overlooked something but is this working recursive into objects?

Copy link
Member Author

Choose a reason for hiding this comment

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

parse_mode: undefined shouldnt match null?

< undefined === null
> false
< undefined == null
> true

Welcome to JS.

Maybe I overlooked something but is this working recursive into objects?

yield valuePart(key, typeof value === "object" ? str(value) : value);
calls
return JSON.stringify(value, (_, v) => v ?? undefined);
which already replaces null values by undefined, which will be removed during serialisation.

Copy link
Member

Choose a reason for hiding this comment

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

Welcome to JS.

Readable code is fun :D

Copy link
Member Author

Choose a reason for hiding this comment

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

It's consistent with the rest of the ecosystem. It's also less verbose than value === undefined || value === null but I do see that point that it could be more readable to use the long version.

Copy link
Member

@EdJoPaTo EdJoPaTo left a comment

Choose a reason for hiding this comment

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

Just tested, this fix works ✨

@KnorpelSenf KnorpelSenf merged commit dad1ce9 into main Dec 28, 2021
@KnorpelSenf KnorpelSenf deleted the no-undefined-in-form-data branch December 28, 2021 18:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Fixes a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: undefined and unspecified have different behavior
2 participants