fix(cache): include query in cache key when opts.path is undefined#5081
Merged
mcollina merged 1 commit intonodejs:mainfrom Apr 21, 2026
Merged
Conversation
makeCacheKey used pathHasQueryOrFragment(opts.path) to decide whether to
merge opts.query into the cached path, but opts.path can be undefined
when a caller supplies only origin+query at dispatch time. In that case
the check threw TypeError ("Cannot read properties of undefined (reading
'includes')"), so the query was never folded into the cache key and
requests with differing queries could collide or the key construction
itself could fail.
Check the already-defaulted fullPath ('/' when opts.path is missing)
instead, so the query is consistently serialised into key.path and
different query strings get separate cache entries regardless of how
path is supplied.
Refs nodejs#4209
Signed-off-by: Maruthan G <maruthang4@gmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5081 +/- ##
==========================================
+ Coverage 93.10% 93.12% +0.01%
==========================================
Files 110 110
Lines 35807 35807
==========================================
+ Hits 33339 33345 +6
+ Misses 2468 2462 -6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
mcollina
pushed a commit
that referenced
this pull request
Apr 29, 2026
…5081) makeCacheKey used pathHasQueryOrFragment(opts.path) to decide whether to merge opts.query into the cached path, but opts.path can be undefined when a caller supplies only origin+query at dispatch time. In that case the check threw TypeError ("Cannot read properties of undefined (reading 'includes')"), so the query was never folded into the cache key and requests with differing queries could collide or the key construction itself could fail. Check the already-defaulted fullPath ('/' when opts.path is missing) instead, so the query is consistently serialised into key.path and different query strings get separate cache entries regardless of how path is supplied. Refs #4209 Signed-off-by: Maruthan G <maruthang4@gmail.com> (cherry picked from commit 1f57375)
Merged
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.
This relates to...
Fixes #4209
Rationale
makeCacheKeyinlib/util/cache.jsgated the merge ofopts.queryinto the cache key onpathHasQueryOrFragment(opts.path). However,opts.pathis optional — callers can dispatch with onlyorigin+query, in which caseopts.pathisundefined. Calling.includes('?')onundefinedthrewTypeError: Cannot read properties of undefined (reading 'includes'), so the query was never folded intokey.pathand requests with differing query strings could collide in the cache (or fail outright).The fix is a one-line change: check the already-defaulted
fullPath(which falls back to'/'whenopts.pathis missing) instead of the rawopts.path. This keeps the existing behavior for callers that embed the query directly inpath, while correctly serialisingopts.queryinto the cache key whenpathis not provided.Changes
Guard
makeCacheKey's query-merge branch against an undefinedopts.pathby inspecting the defaultedfullPath, and add a regression test covering the four path/query permutations.Features
N/A
Bug Fixes
opts.pathis undefined (interceptors.cacheis not aware ofquery? #4209).Breaking Changes and Deprecations
None.
Status