Skip to content

Release 1.11.1 #408

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 14, 2025
Merged
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
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# 1.11.1 (Common, Node.js, Web)

## Bug fixes

- Fixed an issue with URLEncoded special characters in the URL configuration for username or password. ([#407](https://github.com/ClickHouse/clickhouse-js/issues/407))

## Improvements

- Added support for streaming on 32-bit platforms. ([#403](https://github.com/ClickHouse/clickhouse-js/pull/403), [shevchenkonik](https://github.com/shevchenkonik))

# 1.11.0 (Common, Node.js, Web)

## New features
Expand Down
8 changes: 4 additions & 4 deletions packages/client-common/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,12 +320,12 @@ export function loadConfigOptionsFromURL(
handleExtraURLParams: HandleImplSpecificURLParams | null,
): [URL, BaseClickHouseClientConfigOptions] {
let config: BaseClickHouseClientConfigOptions = {}
if (url.username.trim() !== '') {
config.username = url.username
// trim is not needed, cause space is not allowed in the URL basic auth and should be encoded as %20
if (url.username !== '') {
config.username = decodeURIComponent(url.username)
}
// no trim for password
if (url.password !== '') {
config.password = url.password
config.password = decodeURIComponent(url.password)
}
if (url.pathname.trim().length > 1) {
config.database = url.pathname.slice(1)
Expand Down
2 changes: 1 addition & 1 deletion packages/client-common/src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default '1.11.0'
export default '1.11.1'
34 changes: 34 additions & 0 deletions packages/client-node/__tests__/unit/node_client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,39 @@ describe('[Node.js] createClient', () => {
} satisfies CreateConnectionParams)
expect(createConnectionStub).toHaveBeenCalledTimes(1)
})

it('should parse username and password with special characters', async () => {
const username = '! $'
const password = '(#%%@) '
const auth = `${encodeURIComponent(username)}:${encodeURIComponent(password)}`
createClient({
url:
`https://${auth}@my.host:8443/analytics?` +
[
// base config parameters
'application=my_app',
'pathname=my_proxy',
'request_timeout=42000',
'http_header_X-ClickHouse-Auth=secret_token',
// Node.js specific
'keep_alive_idle_socket_ttl=1500',
].join('&'),
})
expect(createConnectionStub).toHaveBeenCalledWith({
connection_params: {
...params,
url: new URL('https://my.host:8443/my_proxy'),
auth: { username, password, type: 'Credentials' },
},
tls: undefined,
keep_alive: {
enabled: true,
idle_socket_ttl: 1500,
},
set_basic_auth_header: true,
http_agent: undefined,
} satisfies CreateConnectionParams)
expect(createConnectionStub).toHaveBeenCalledTimes(1)
})
})
})
19 changes: 13 additions & 6 deletions packages/client-node/src/utils/stream.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import Stream from 'stream'
import { constants } from 'buffer'

// See https://github.com/v8/v8/commit/ea56bf5513d0cbd2a35a9035c5c2996272b8b728
const MaxStringLength = Math.pow(2, 29) - 24
const { MAX_STRING_LENGTH } = constants

export function isStream(obj: any): obj is Stream.Readable {
return obj !== null && typeof obj.pipe === 'function'
export function isStream(obj: unknown): obj is Stream.Readable {
return (
typeof obj === 'object' &&
obj !== null &&
'pipe' in obj &&
typeof obj.pipe === 'function' &&
'on' in obj &&
typeof obj.on === 'function'
)
}

export async function getAsText(stream: Stream.Readable): Promise<string> {
Expand All @@ -13,10 +20,10 @@ export async function getAsText(stream: Stream.Readable): Promise<string> {
const textDecoder = new TextDecoder()
for await (const chunk of stream) {
const decoded = textDecoder.decode(chunk, { stream: true })
if (decoded.length + text.length > MaxStringLength) {
if (decoded.length + text.length > MAX_STRING_LENGTH) {
throw new Error(
'The response length exceeds the maximum allowed size of V8 String: ' +
`${MaxStringLength}; consider limiting the amount of requested rows.`,
`${MAX_STRING_LENGTH}; consider limiting the amount of requested rows.`,
)
}
text += decoded
Expand Down
2 changes: 1 addition & 1 deletion packages/client-node/src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default '1.11.0'
export default '1.11.1'
2 changes: 1 addition & 1 deletion packages/client-web/src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default '1.11.0'
export default '1.11.1'