fix: hasRequestDecorator/hasReplyDecorator misses constructor-assigned built-in properties#6753
Merged
Eomm merged 2 commits intoJun 28, 2026
Merged
Conversation
…-assigned built-in properties
Properties like req.id, req.params, req.body, reply.raw, and reply.log
are set directly in the Request and Reply constructors rather than on
their prototypes. Because of this, hasRequestDecorator('id') returned
false and decorateRequest('id', null) silently succeeded, overwriting
the built-in value and causing a TypeError at request time.
This adds an instanceProperties set to Request and Reply listing those
constructor-assigned string-keyed properties, and teaches
decorateConstructor and the existence helpers to check that set.
hasRequestDecorator('id') now returns true, and decorateRequest('id')
now throws FST_ERR_DEC_ALREADY_PRESENT as expected.
metcoder95
approved these changes
Jun 5, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes incorrect decorator-existence checks for core Request/Reply properties that are assigned in their constructors (rather than on prototypes), ensuring hasRequestDecorator / hasReplyDecorator and decoration collision detection behave correctly for built-in fields like req.id and reply.raw.
Changes:
- Add explicit
instancePropertiessets tolib/request.jsandlib/reply.jsto enumerate constructor-assigned built-in properties. - Extend
lib/decorate.jschecks to treat those instance properties as already-present when callinghas*Decoratorand when decorating request/reply constructors. - Add new tests covering
has*Decoratorcorrectness and duplicate-decoration protection for these built-ins.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| test/decorator-instance-properties.test.js | Adds regression tests for built-in constructor-assigned request/reply properties and decoration collision behavior. |
| lib/request.js | Introduces Request.instanceProperties to list built-in constructor-assigned request fields. |
| lib/reply.js | Introduces Reply.instanceProperties to list built-in constructor-assigned reply fields. |
| lib/decorate.js | Updates decoration/existence logic to consider constructor-assigned instance properties (including walking parent constructors). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Eomm
approved these changes
Jun 15, 2026
Member
|
ping @jean-michelet |
Member
|
I didn't block it, you can merge. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
hasRequestDecoratorandhasReplyDecoratoronly check the constructor prototype and the decorator props list. But several core properties —req.id,req.params,req.raw,req.query,req.log,req.body,reply.raw,reply.request,reply.log— are assigned directly in theRequestandReplyconstructors, not on their prototypes.This means:
Root cause
checkRequestExistenceanddecorateConstructorinlib/decorate.jsuseObject.hasOwn(prototype, name)andname in prototype. Properties set in the constructor body are never on the prototype, so these checks miss them.Fix
Add an
instancePropertiesset toRequestandReplylisting their constructor-assigned string-keyed properties.decorateConstructorand thecheckRequest/ReplyExistencehelpers now also check this set (walking the parent chain for derived constructors).After the fix:
All 52 existing decorator tests pass. Six new node:test tests cover the bug and the fix.