Skip to content

Fix percent-encoded database names in connection URL paths - #977

Open
fallintoplace wants to merge 2 commits into
ClickHouse:mainfrom
fallintoplace:fix/decode-database-url-path
Open

Fix percent-encoded database names in connection URL paths#977
fallintoplace wants to merge 2 commits into
ClickHouse:mainfrom
fallintoplace:fix/decode-database-url-path

Conversation

@fallintoplace

@fallintoplace fallintoplace commented Jul 30, 2026

Copy link
Copy Markdown

Problem

The WHATWG URL API exposes pathname in percent-encoded form. The client copied the database path directly into config.database, then URLSearchParams encoded its percent signs again when building a request:

URL path:       /my%20database
Parsed before:  my%20database
Request before: database=my%2520database

Spaces, Unicode characters, and literal percent signs were therefore sent with the wrong database name.

Fix

Decode the database path when converting it from its URL representation into configuration, consistent with the existing username and password handling. Request serialization then performs the single required encoding pass.

Only database names parsed from URL paths are decoded. Values supplied directly through the database option retain their existing semantics; a regression test pins that boundary.

The Node.js and Web clients both use the shared source through their src/common symlinks, and both unit suites run these tests. Their changelogs document the fix.

Validation

  • npm run test:node:unit (412 passed, 4 skipped)
  • npm run test:web:unit (261 passed)
  • npm run build
  • npm run typecheck
  • npm run lint
  • npm run prettier:check

Copilot AI review requested due to automatic review settings July 30, 2026 17:43

Copilot AI 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.

Pull request overview

This PR aims to fix double-encoded database names when a database is provided via the URL path (e.g. /my%20database previously becoming database=my%2520database), by decoding the path segment during URL config parsing and adding regression tests.

Changes:

  • Decode url.pathname (minus the leading /) when mapping it to config.database.
  • Add unit regression cases for spaces, Unicode, and literal % sequences in database names.
  • Add a changelog entry describing the fix.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
packages/client-common/src/config.ts Decodes the database name extracted from the URL path.
packages/client-common/tests/unit/config.test.ts Adds parameterized tests verifying correct decoding behavior.
packages/client-common/CHANGELOG.md Documents the bug fix in the changelog.

Comment thread packages/client-common/src/config.ts
Comment thread packages/client-common/__tests__/unit/config.test.ts
Comment thread packages/client-common/CHANGELOG.md Outdated
Copilot AI review requested due to automatic review settings July 30, 2026 17:49
@fallintoplace fallintoplace changed the title Fix double-encoded database names from URL paths Fix double encoding of database names from connection URLs Jul 30, 2026

Copilot AI 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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (2)

packages/client-common/src/config.ts:502

  • decodeURIComponent(url.pathname.slice(1)) can throw a URIError on malformed percent-encoding (e.g. stray %), which would currently bubble up without any ClickHouse-specific context. Consider catching decode failures and rethrowing a clear error so config parsing fails deterministically and with an actionable message.
  if (url.pathname.trim().length > 1) {
    config.database = decodeURIComponent(url.pathname.slice(1));
  }

packages/client-common/src/config.ts:502

  • This change modifies code under packages/client-common, but the PR only updates the Node/Web package changelogs. If @clickhouse/client-common is still published from this repo (it is private: false), it likely also needs a changelog entry (or a note in the PR description clarifying why it is intentionally excluded despite code changes).
  if (url.pathname.trim().length > 1) {
    config.database = decodeURIComponent(url.pathname.slice(1));
  }

Copilot AI review requested due to automatic review settings July 30, 2026 17:55
@fallintoplace fallintoplace changed the title Fix double encoding of database names from connection URLs Decode percent-encoded database names from connection URL paths Jul 30, 2026

Copilot AI 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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

packages/client-common/src/config.ts:502

  • decodeURIComponent(url.pathname.slice(1)) can throw a URIError (e.g. when the URL contains a bare % or otherwise-invalid percent-encoding). Since prepareConfigWithURL doesn’t catch that, this change can surface an opaque URIError: URI malformed to users when the database name comes from the URL path. Consider catching decode failures here and rethrowing a ClickHouse-specific error message (with the original error as cause) so mis-encoded URLs fail with a clear diagnosis.
  if (url.pathname.trim().length > 1) {
    config.database = decodeURIComponent(url.pathname.slice(1));
  }

Copilot AI review requested due to automatic review settings July 30, 2026 17:59
@fallintoplace
fallintoplace force-pushed the fix/decode-database-url-path branch from b3c54c5 to 2f2b6b6 Compare July 30, 2026 17:59
@fallintoplace
fallintoplace force-pushed the fix/decode-database-url-path branch from 2f2b6b6 to 1d94617 Compare July 30, 2026 18:00
@fallintoplace fallintoplace changed the title Decode percent-encoded database names from connection URL paths Fix percent-encoded database names in connection URL paths Jul 30, 2026

Copilot AI 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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings July 30, 2026 18:01

Copilot AI 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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

Copilot AI 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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

@mshustov
mshustov requested a review from Copilot August 4, 2026 19:15

Copilot AI 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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

Suppressed comments (1)

packages/client-common/src/config.ts:502

  • decodeURIComponent can throw URIError: URI malformed if the path contains an invalid percent-escape sequence. With this change, that error would bubble up without context (unlike createUrl, which wraps malformed URLs). Consider wrapping the decode in a try/catch and throwing a ClickHouse-specific error message so users can diagnose bad URLs more easily.
  if (url.pathname.trim().length > 1) {
    config.database = decodeURIComponent(url.pathname.slice(1));
  }

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.

3 participants