Skip to content

[client-v2, jdbc-v2] Fix handling strings with special characters #2781

Description

@chernser

Description

This is original problem ClickHouse/ClickHouse#99015:


Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry:

Named String query parameters containing literal tab (0x09) or newline (0x0a) bytes fail with BAD_QUERY_PARAMETER ("isn't parsed completely") when sent via the native TCP protocol.


Bug description

When a String named query parameter contains a literal tab or newline character, the server throws:

Value hello	world cannot be parsed as String for query parameter 'param_x'
because it isn't parsed completely: only 5 of 11 bytes was parsed: hello

Root cause

There is a format mismatch across three layers in the native TCP parameter path:

  1. Settings::toNameToNameMap() (src/Core/Settings.cpp:8217) decodes the Field dump format to raw bytes via readQuoted — so a tab stored as \t in the dump becomes a literal 0x09 byte in query_parameters.

  2. ReplaceQueryParameterVisitor::visitQueryParameter() (src/Interpreters/ReplaceQueryParameterVisitor.cpp:143) then passes this raw value to deserializeTextEscaped.

  3. deserializeTextEscaped → readEscapedStringIntoImpl (src/IO/ReadHelpers.cpp:659) treats raw 0x09 (tab) and 0x0a (newline) as TSV field delimiters, stopping the parse early. The remaining bytes cause the !read_buffer.eof() check at line 151 to throw.

The same bug exists for the HTTP interface when the parameter value is URL-encoded as %09 or %0A.

Workaround

Double-escape the character on the client side — pass \\t (backslash + t) instead of a literal tab. The extra backslash survives the Field dump round-trip as a single backslash, giving deserializeTextEscaped the two-char \t sequence it expects.

Test

The test includes:

  • A baseline (simple string, works)
  • The \\t workaround (works)
  • Two cases demonstrating the bug (tab and newline, currently fail with the error above)
  • Two cases showing the expected behaviour after the fix (currently failing — these should pass once the server-side bug is fixed)

Activity

  1. added this to the 0.9.9 milestone on Mar 18, 2026
  2. modified the milestones: 0.9.9, 0.9.10 on Mar 31, 2026
  3. kishansinghifs1 commented on Jun 16, 2026

    @kishansinghifs1
    Contributor

    Hiii @chernser can I work on this ?

  4. mshustov commented on Jul 27, 2026

    @mshustov
    Member

    @polyglotAI-bot please fix this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions