Skip to content

fix(urlencoded): emit fieldsLimit when the limit is hit inside a chunk - #242

Merged
mcollina merged 1 commit into
fastify:mainfrom
ismailtrm:fieldslimit-single-chunk
Dec 4, 2026
Merged

mcollina merged 1 commit into
fastify:mainfrom
ismailtrm:fieldslimit-single-chunk

Conversation

@ismailtrm

Copy link
Copy Markdown
Contributor

With limits: { fields: 1 }, the body a=1&b=2&c=3 gives one field event for a and then finish; fieldsLimit never fires. If the same body arrives as a=1& and b=2&c=3, it does, because the limit is only checked again at the start of the next write(). Small form bodies often come in as a single chunk, so the event is missing in the common case, although the README says it is emitted when the limit is reached.

fieldsLimit is now emitted where the limit is reached, as long as the chunk still has bytes after that point. A body that ends exactly at the limit (a=1&) still emits nothing, as it does today when it is split.

The urlencoded test table now also counts fieldsLimit events, with new cases for a body split after the limit, one that ends at it, and a later write after the event.

Checklist

The fields limit was only reported at the start of the next write(),
so a body that arrived in one chunk dropped the extra fields without
ever emitting fieldsLimit. Emit it where the limit is reached when
bytes remain in the chunk.

Signed-off-by: Ismail Tarim <ismailtarim7@gmail.com>
@ismailtrm

Copy link
Copy Markdown
Contributor Author

@mcollina gentle ping on this one. It's a small follow-up in lib/types/urlencoded.js, next to the 3.2.6 size-limit fix: fieldsLimit is never emitted when the whole body arrives in one chunk.

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm

@mcollina
mcollina merged commit 7c861ed into fastify:main Dec 4, 2026
19 checks passed
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