Skip to content

fix(http): keep the existing query string when adding params on web - #8629

Open
breken-ai wants to merge 1 commit into
ionic-team:mainfrom
breken-ai:fix/http-web-url-query
Open

breken-ai wants to merge 1 commit into
ionic-team:mainfrom
breken-ai:fix/http-web-url-query

Conversation

@breken-ai

Copy link
Copy Markdown

Description

The web implementation of CapacitorHttp.request() always joins params with ?:

const url = urlParams ? `${options.url}?${urlParams}` : options.url;

When url already has a query string, the request goes to a URL with two ?:

CapacitorHttp.get({ url: 'https://example.com/api?a=1', params: { b: '2' } });
// fetches https://example.com/api?a=1?b=2
// the server sees a = "1?b=2" and no b

The Android (HttpRequestHandler.java) and iOS (HttpRequestHandler.swift) implementations keep the existing query and add the params to it, so the same call behaves differently on web. This PR uses & when the URL already contains ?.

Change Type

  • Fix
  • Feature
  • Refactor
  • Breaking Change
  • Documentation
  • Other (CI, chores, etc.)

Rationale / Problems Fixed

Any web call that combines a URL with a query string (for example a signed URL or a paging link returned by an API) and params sends a wrong request: the first existing parameter gets the rest of the query appended to its value, and the added params are lost.

Tests or Reproductions

Added core/src/tests/http.spec.ts, which mocks fetch and checks the URL passed to it:

  • appends params to a url without a query string: passes before and after.
  • keeps the existing query string when adding params: fails before the fix (https://example.com/api?a=1?b=2), passes after (https://example.com/api?a=1&b=2).

npm test in core: all suites pass. eslint and prettier --check are clean on the changed files.

Screenshots / Media

N/A

Platforms Affected

  • Android
  • iOS
  • Web

Notes / Comments

This does not touch the array && issue in buildUrlParams (#8270 / #8272); the two changes are independent.

I found this while reading the code with an AI assistant (Claude); I checked the failing test and the fix myself.

🤖 Generated with Claude Code

The web CapacitorHttp request joined params with '?' even when the url already had a query string, producing url?a=1?b=2. Use '&' in that case, matching Android and iOS.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant