fix: prevent crash when BigInt passed to res.status()
Fixes #6756
Previously, passing a BigInt to res.status() would cause an uncaught TypeError because JSON.stringify() cannot serialize BigInt values. The error occurred when trying to create the error message.
Changes:
- Replace JSON.stringify(code) with template literal and typeof
- Error message now shows both the value and its type
- Add comprehensive tests for BigInt and other invalid types
This is a duplicate of #6848, with the same approach.
This is a duplicate of #6848, with the same approach.
Thanks for pointing out the Object.create(null) edge case!
I've updated this PR to handle it properly. The fix now uses:
-
Object.prototype.toString.call(code)for objects (handles null-prototype objects safely) -
String(code)for primitives (handles BigInt correctly)
Added a test case specifically for Object.create(null) to verify the fix.
All 13 tests pass
There's no crash here. Im sorry but misunderstanding the problem you're attempting to solve is a close from me.