fix(buildURL): reject nullish url instead of coercing it to an empty string by lazerg · Pull Request #11162 · axios/axios · GitHub
Skip to content

fix(buildURL): reject nullish url instead of coercing it to an empty string - #11162

Open
lazerg wants to merge 4 commits into
axios:v1.xfrom
lazerg:fix/issue-11160-nullish-url
Open

fix(buildURL): reject nullish url instead of coercing it to an empty string#11162
lazerg wants to merge 4 commits into
axios:v1.xfrom
lazerg:fix/issue-11160-nullish-url

Conversation

@lazerg

@lazerg lazerg commented Aug 20, 2026

Copy link
Copy Markdown

Summary

#10959 added url = url || '' to buildURL to stop a TypeError when params were passed with an undefined url. That guard also changed what a nullish url means. axios.get(null, { params }) used to blow up before any request went out; since 1.18.1 it builds ?foo=bar, which the browser resolves against the current page, so the app silently fires a request at itself.

The empty string is a legitimate relative url and should keep working. null and undefined are not, and they should not quietly become one. This restores the fail-fast behavior without bringing back the raw TypeError: a non-string url with params now throws an AxiosError carrying ERR_INVALID_URL, the same code buildFullPath already uses for unusable urls. Values such as 0, false and a URL instance previously reached url.indexOf and died with a bare TypeError, so they are covered by the same check. A url that comes from baseURL alone is unaffected, since combineURLs has already turned it into a string by then.

Scope is deliberately limited to the params path, which is the part #10959 changed. axios.get(null) without params returns early at if (!params) and behaves exactly as it did before 1.18.1.

Linked issue

Closes #11160

Changes

  • lib/helpers/buildURL.js: throw AxiosError / ERR_INVALID_URL for a non-string url instead of coercing it to ''.
  • tests/unit/helpers/buildURL.test.js: cover the rejection and keep the empty-string case explicit.
  • tests/unit/helpers/resolveConfig.test.js: regression test for the reported path, a null url plus params no longer resolves to the current page.
  • PRE_RELEASE_CHANGELOG.md: note the fix.

Testing

  • npx eslint lib/helpers/buildURL.js
  • npm run test:vitest:unit — 58 files, 1,064 tests passed

Checklist

  • Tests added or updated
  • No public API type change
  • Behavior change is intentional and restores pre-1.18.1 semantics for nullish urls

@lazerg
lazerg requested a review from jasonsaayman as a code owner August 20, 2026 10:16

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 4 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread lib/helpers/buildURL.js Outdated
@greptile-apps

greptile-apps Bot commented Aug 20, 2026

Copy link
Copy Markdown

Comment thread lib/helpers/buildURL.js Outdated
Comment thread lib/helpers/buildURL.js

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 3 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread lib/helpers/buildURL.js
@jasonsaayman jasonsaayman added commit::fix The PR is related to a bugfix v1x Version 1 labels Sep 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commit::fix The PR is related to a bugfix v1x Version 1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Null URLs fallback on '' which has a different behavior

2 participants