{{ message }}
fix: fallback to GET when config.method is undefined in adapters (closes #6960)#10683
Open
MarcosNocetti wants to merge 2 commits intoaxios:v1.xfrom
Open
fix: fallback to GET when config.method is undefined in adapters (closes #6960)#10683MarcosNocetti wants to merge 2 commits intoaxios:v1.xfrom
MarcosNocetti wants to merge 2 commits intoaxios:v1.xfrom
Conversation
Adds defensive (config.method || 'get') fallback in xhr, http, and fetch adapters before calling .toUpperCase(). This prevents TypeError when an interceptor removes config.method after Axios._request() normalization. Includes regression test. Closes axios#6960
Contributor
There was a problem hiding this comment.
1 issue found across 4 files
Confidence score: 3/5
- There is a concrete regression risk in
lib/adapters/fetch.js:methodfallback happens after upload preprocessing, so an undefined method can be treated as non-GET during preprocessing before later being coerced to GET. - Given the medium severity (6/10) and high confidence (8/10), this is more than a cosmetic issue and could affect request behavior for callers that omit
method. - Pay close attention to
lib/adapters/fetch.js- ensure method normalization happens before any method-dependent upload preprocessing.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="lib/adapters/fetch.js">
<violation number="1" location="lib/adapters/fetch.js:240">
P2: Method fallback is applied too late: undefined `method` can pass non-GET upload preprocessing before being coerced to GET in `resolvedOptions`.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
The (method || 'get') fallback was applied at resolvedOptions (line 240) but undefined method would incorrectly pass the upload preprocessing guard (method !== 'get' && method !== 'head') at line 190, causing unnecessary Request/stream creation for what should be a GET request. Moves the fallback to right after destructuring so all downstream code sees a valid method string.
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.

Summary
(config.method || 'get')fallback before.toUpperCase()in all 3 adaptersTypeError: undefined is not an object (evaluating 'config.method.toUpperCase')Root Cause
Axios._request()normalizesconfig.methodat line 145, but request interceptors run after this normalization and can delete or nullifyconfig.method. The adapters then crash when calling.toUpperCase()onundefined.Changes
lib/adapters/xhr.js:36_config.method.toUpperCase()→(_config.method || 'get').toUpperCase()lib/adapters/http.js:338config.method.toUpperCase()→(config.method || 'get').toUpperCase()lib/adapters/fetch.js:240method.toUpperCase()→(method || 'get').toUpperCase()tests/unit/regression/method-undefined.test.jsThe
'get'default matches the same fallback already used inAxios.js:145.Test plan
npx vitest run tests/unit/regression/method-undefined.test.js(2/2)Summary by cubic
Prevents crashes when
config.methodis unset by defaulting toGETacross adapters and fixesfetchpreprocessing to avoid unnecessary upload handling. Adds a regression test to guard against future breakage (closes #6960).Description
(config.method || 'get').toUpperCase()before use.method = method || 'get'immediately after destructuring so upload guards see the correct method.config.methodafter normalization, making.toUpperCase()throw and causing incorrect fetch upload preprocessing.axiosdefaults.Testing
tests/unit/regression/method-undefined.test.js(2 cases):GETwhen an interceptor removesconfig.method.httpadapter does not throwTypeErrorwhenmethodisundefined.Written for commit 7bc149c. Summary will update on new commits.