Skip to content

fix(think-router): do not write caller options into the shared default options - #1794

Merged
lizheming merged 2 commits into
thinkjs:masterfrom
lee3Q:fix/router-default-options-leak
Nov 4, 2026
Merged

lizheming merged 2 commits into
thinkjs:masterfrom
lee3Q:fix/router-default-options-leak

Conversation

@lee3Q

@lee3Q lee3Q commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

parseRouter does Object.assign(defaultOptions, options), which writes the caller's options into the module-level defaultOptions. A later call such as parseRouter({}) then inherits the earlier call's settings (for example defaultAction or prefix).

This uses Object.assign({}, defaultOptions, options) so each call gets a fresh options object. Nested arrays and objects are still shared by reference, as before.

Compatibility note: code that relied on options from an earlier call carrying over to later calls will now get the defaults. In this monorepo only packages/thinkjs re-exports think-router.

Test: added a case where the first call sets defaultController: 'first' and a second call with {} must use index.

node --test --test-concurrency=1 test/index.js in packages/think-router (Node v22.23.4):

  • base with the new test: 43 tests, 42 pass, 1 fail
  • with the fix: 43 pass, 0 fail
  • npx eslint index.js: exit 0

@codecov

codecov Bot commented Nov 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.75%. Comparing base (3d23253) to head (69580aa).
⚠️ Report is 6 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1794   +/-   ##
=======================================
  Coverage   72.75%   72.75%           
=======================================
  Files         241      241           
  Lines       19183    19183           
=======================================
  Hits        13956    13956           
  Misses       5227     5227           
Components Coverage Δ
think-apollo-graphql 0.00% <ø> (ø)
think-awesome ∅ <ø> (∅)
think-babel 100.00% <ø> (ø)
think-cache 100.00% <ø> (ø)
think-cache-file 100.00% <ø> (ø)
think-cache-memcache 0.00% <ø> (ø)
think-cache-redis 96.82% <ø> (ø)
think-cli 39.70% <ø> (ø)
think-cluster 78.90% <ø> (ø)
think-config 100.00% <ø> (ø)
think-controller 100.00% <ø> (ø)
think-crontab 100.00% <ø> (ø)
think-csrf 98.38% <ø> (ø)
think-debounce 100.00% <ø> (ø)
think-demo 0.00% <ø> (ø)
think-email 0.00% <ø> (ø)
think-fetch 100.00% <ø> (ø)
think-gc 100.00% <ø> (ø)
think-helmet 100.00% <ø> (ø)
think-helper 99.15% <ø> (ø)
think-i18n 49.19% <ø> (ø)
think-inspect 100.00% <ø> (ø)
think-instance 100.00% <ø> (ø)
think-knex 100.00% <ø> (ø)
think-loader 90.57% <ø> (ø)
think-logger 68.29% <ø> (ø)
think-logger3 68.07% <ø> (ø)
think-logic 100.00% <ø> (ø)
think-memcache 0.00% <ø> (ø)
think-meta 100.00% <ø> (ø)
think-mock 0.00% <ø> (ø)
think-mock-http 87.93% <ø> (ø)
think-model 88.58% <ø> (ø)
think-model-abstract 96.19% <ø> (ø)
think-model-mysql 95.70% <ø> (ø)
think-model-mysql2 95.70% <ø> (ø)
think-model-postgresql 97.97% <ø> (ø)
think-model-sqlite 88.96% <ø> (ø)
think-mongo 0.00% <ø> (ø)
think-mongoose 60.08% <ø> (ø)
think-mysql 89.66% <ø> (ø)
think-mysql2 89.66% <ø> (ø)
think-pagination 98.42% <ø> (ø)
think-payload 97.95% <ø> (ø)
think-pm2 100.00% <ø> (ø)
think-proxy 91.07% <ø> (ø)
think-qs 100.00% <ø> (ø)
think-ratelimiter 0.00% <ø> (ø)
think-redis 97.57% <ø> (ø)
think-resource 100.00% <ø> (ø)
think-router 100.00% <100.00%> (ø)
think-router-rest 93.93% <ø> (ø)
think-sequelize 47.84% <ø> (ø)
think-session 97.79% <ø> (ø)
think-session-cookie 97.63% <ø> (ø)
think-session-file 96.02% <ø> (ø)
think-session-jwt 100.00% <ø> (ø)
think-session-mysql 27.85% <ø> (ø)
think-session-redis 95.00% <ø> (ø)
think-store-file 87.67% <ø> (ø)
think-svg-captcha 100.00% <ø> (ø)
think-trace 60.25% <ø> (ø)
think-typescript 100.00% <ø> (ø)
think-validator 100.00% <ø> (ø)
think-view 56.11% <ø> (ø)
think-view-ejs 100.00% <ø> (ø)
think-view-handlebars 100.00% <ø> (ø)
think-view-nunjucks 100.00% <ø> (ø)
think-view-pug 100.00% <ø> (ø)
think-watcher 98.91% <ø> (ø)
think-websocket 100.00% <ø> (ø)
think-websocket-socket.io 100.00% <ø> (ø)
think-websocket-ws 0.00% <ø> (ø)
thinkjs 94.87% <ø> (ø)
Files with missing lines Coverage Δ
packages/think-router/index.js 100.00% <100.00%> (ø)

Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3d23253...69580aa. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@lizheming
lizheming merged commit fdd5f50 into thinkjs:master Nov 4, 2026
80 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