Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions packages/client-common/__tests__/unit/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
getConnectionParams,
LogWriter,
numberConfigURLValue,
toSearchParams,
} from "../../src/index";
import { TestLogger } from "../utils/test_logger";
import type { BaseClickHouseClientConfigOptionsWithURL } from "../../src/config";
Expand All @@ -33,6 +34,16 @@ describe("config", () => {
expect(res).toEqual(defaultConfig);
});

it("should preserve percent sequences in the database option", () => {
const config = prepareConfigWithURL(
{ database: "my%20database" },
logger,
null,
);

expect(config.database).toBe("my%20database");
});

it("should fall back to default HTTP/HTTPS port numbers", async () => {
expect(
prepareConfigWithURL({ url: "http://localhost:80" }, logger, null),
Expand Down Expand Up @@ -971,6 +982,32 @@ describe("config", () => {
});
});

it.each([
["spaces", "my%20database", "my database", "my+database"],
["Unicode characters", "分析", "分析", "%E5%88%86%E6%9E%90"],
[
"literal percent signs",
"my%2520database",
"my%20database",
"my%2520database",
],
])(
"should decode %s in database names from URL paths",
(_characters, path, database, encodedDatabase) => {
const url = new URL(`http://localhost:8124/${path}`);
const [, config] = loadConfigOptionsFromURL(url, null);
const searchParams = toSearchParams({
database: config.database,
query_id: "query-id",
});

expect(config.database).toBe(database);
expect(searchParams.toString().split("&")).toContain(
`database=${encodedDatabase}`,
);
},
);
Comment thread
fallintoplace marked this conversation as resolved.

it("should load only the settings from the URL, without auth", async () => {
const url = new URL(
"http://localhost:8124/?" +
Expand Down
2 changes: 1 addition & 1 deletion packages/client-common/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ export function loadConfigOptionsFromURL(
config.password = decodeURIComponent(url.password);
}
if (url.pathname.trim().length > 1) {
config.database = url.pathname.slice(1);
config.database = decodeURIComponent(url.pathname.slice(1));
}
Comment thread
fallintoplace marked this conversation as resolved.
const urlSearchParamsKeys = [...url.searchParams.keys()];
if (urlSearchParamsKeys.length > 0) {
Expand Down
3 changes: 3 additions & 0 deletions packages/client-node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@

## Bug fixes

- Fixed database names from URL paths being percent-encoded twice when they contain spaces, Unicode characters, or literal percent signs. ([#977])

- Fixed `Array(Date)` / `Array(Date32)` query-parameter binding (and other temporal element types nested in arrays, tuples, and maps). A JS `Date` inside a container was serialized as a bare Unix timestamp (e.g. `[1683244800]`), which the server's `Array(Date)` element parser rejects (`CANNOT_PARSE_INPUT_ASSERTION_FAILED`). Container-nested `Date` values are now emitted as a quoted UTC date string (e.g. `['2023-05-05']`), the one encoding every temporal element type accepts. Note: a `Date` used inside `Array(DateTime)` / `Array(DateTime64)` is now bound at day precision (the time-of-day is dropped), since date-only is the only form `Array(Date)` accepts; scalar `Date` / `DateTime` binding is unchanged. ([#947])

[#947]: https://github.com/ClickHouse/clickhouse-js/pull/947
[#977]: https://github.com/ClickHouse/clickhouse-js/pull/977

# 1.23.1

Expand Down
3 changes: 3 additions & 0 deletions packages/client-web/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@

## Bug fixes

- Fixed database names from URL paths being percent-encoded twice when they contain spaces, Unicode characters, or literal percent signs. ([#977])

- Fixed `Array(Date)` / `Array(Date32)` query-parameter binding (and other temporal element types nested in arrays, tuples, and maps). A JS `Date` inside a container was serialized as a bare Unix timestamp (e.g. `[1683244800]`), which the server's `Array(Date)` element parser rejects (`CANNOT_PARSE_INPUT_ASSERTION_FAILED`). Container-nested `Date` values are now emitted as a quoted UTC date string (e.g. `['2023-05-05']`), the one encoding every temporal element type accepts. Note: a `Date` used inside `Array(DateTime)` / `Array(DateTime64)` is now bound at day precision (the time-of-day is dropped), since date-only is the only form `Array(Date)` accepts; scalar `Date` / `DateTime` binding is unchanged. ([#947])

[#947]: https://github.com/ClickHouse/clickhouse-js/pull/947
[#977]: https://github.com/ClickHouse/clickhouse-js/pull/977

# 1.23.1

Expand Down