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: Update body_size_limit to use Number instead of parseInt #11589

Merged
merged 7 commits into from
Jan 10, 2024
Merged

fix: Update body_size_limit to use Number instead of parseInt #11589

merged 7 commits into from
Jan 10, 2024

Conversation

codenoid
Copy link
Contributor

Summary
This pull request updates the environment variable handling in our SvelteKit application to support floating-point values for the BODY_SIZE_LIMIT. Previously, the BODY_SIZE_LIMIT was parsed using parseInt, which limited it to integer values. By switching to parseFloat, we can now define more precise limits, improving the flexibility of our application's configuration.

Changes
Changed the parsing method for BODY_SIZE_LIMIT from parseInt to parseFloat. This allows the use of both integers and floating-point numbers, providing more granular control over the body size limit.

Impact
Enhanced Flexibility: Users can now specify decimal values in the BODY_SIZE_LIMIT environment variable, enabling more precise control over request body size limits.

Backward Compatibility: Integer values are still supported. Existing configurations using integer values for BODY_SIZE_LIMIT will continue to work as expected.

BODY_SIZE_LIMIT=Infinity
BODY_SIZE_LIMIT=0x80000
BODY_SIZE_LIMIT=1e5

solve #11580

Copy link

changeset-bot bot commented Jan 10, 2024

🦋 Changeset detected

Latest commit: 892f318

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/adapter-node Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Rich-Harris
Copy link
Member

Thank you — we also need to error if parseFloat(...) returns NaN instead of falling back to undefined, and we need a changeset

@Conduitry
Copy link
Member

I think this should be a feat:, not a fix:. Unless @Rich-Harris you think we should play it safe and call it breaking: because people could conceivably be specifying values that parseInt to NaN?

@codenoid
Copy link
Contributor Author

hi, could you please review my latest change, I'm not sure doing validation on top-level or somewhere

Copy link
Member

@Rich-Harris Rich-Harris left a comment

Choose a reason for hiding this comment

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

we should add a helpful error message in the case where people are currently using 0 to mean 'Infinity'. will do that now

.changeset/chatty-swans-pretend.md Outdated Show resolved Hide resolved
.changeset/chatty-swans-pretend.md Outdated Show resolved Hide resolved
packages/adapter-node/src/handler.js Outdated Show resolved Hide resolved
packages/adapter-node/src/handler.js Show resolved Hide resolved
@Rich-Harris
Copy link
Member

@Conduitry I think we have to call it breaking because we're changing the meaning of 0 from 'Infinity' to 'zero'

@codenoid codenoid changed the title fix: Update body_size_limit to use parseFloat instead of parseInt fix: Update body_size_limit to use Number instead of parseInt Jan 10, 2024
@Rich-Harris Rich-Harris merged commit 0f16e83 into sveltejs:main Jan 10, 2024
12 checks passed
@Rich-Harris
Copy link
Member

thank you!

@github-actions github-actions bot mentioned this pull request Jan 10, 2024
@codenoid
Copy link
Contributor Author

image

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.

3 participants