Skip to content

Reject reserved names in morgan.token() - #385

Open
seethinajayadileep wants to merge 1 commit into
expressjs:masterfrom
seethinajayadileep:fix/reject-reserved-token-names
Open

Reject reserved names in morgan.token()#385
seethinajayadileep wants to merge 1 commit into
expressjs:masterfrom
seethinajayadileep:fix/reject-reserved-token-names

Conversation

@seethinajayadileep

Copy link
Copy Markdown

Summary

morgan.token() stores callbacks on the morgan export object. Registering a token named token, format, or compile therefore overwrote morgan's own API methods. After morgan.token('token', ...), later morgan.token(...) calls failed with TypeError: ... is not a function, which matches issue #265.

Per maintainer guidance on that issue, 1.x should reject those reserved names with a clear error (and document them). Allowing arbitrary names is left for a future 2.0 redesign.

Changes

  • Throw TypeError when registering a reserved token name
  • Document reserved names in the README
  • Add regression tests (reject reserved names; keep morgan.token usable after a rejected registration)

Test plan

  • ./node_modules/.bin/mocha --exit test/morgan.js (96 pass)
  • NO_COLOR=1 ./node_modules/.bin/mocha --exit test/noColor.js (6 pass)

Fixes #265

Registering a token named token/format/compile overwrote morgan's own
API methods because tokens are stored on the export object. Throw a
TypeError instead, document the reserved names, and add regression tests.

Fixes expressjs#265

Signed-off-by: JAYA DILEEP <seethinajayadileep@hotmail.com>
@seethinajayadileep
seethinajayadileep marked this pull request as ready for review September 6, 2026 04:28
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.

Adding a token named token causes all subsequent tokens to break.

1 participant