Bug: parsing escaped enum names
Enum (and Variant element) names can contain escaped single quotes (\'), but the type string parser does not handle escape sequences in quoted strings.
Affected code
clickhouse/types/type_parser.cpp, TypeParser::NextToken(), the case '\'' branch. There is even an existing TODO comment acknowledging the gap:
// TODO (nemkov): handle escaping ?
When the tokenizer scans for the closing ' it does not skip over \' sequences, so a name like 'val\'ue' would be split at the backslash-escaped quote, returning a truncated/incorrect token.
Example
A query such as:
SELECT variantType(CAST(toDateTime('2024-01-15 10:30:00', 'UTC'), 'Variant(String, DateTime(\'UTC\'))'))
returns a Variant type whose element type string contains single-quoted sub-types. When the client tries to parse the returned column type the tokenizer misreads the quoted segment.
Expected behaviour
The parser should treat \' inside a quoted string as an escaped single quote (part of the name), not as the closing delimiter. The stored value should also have the backslash removed (i.e. \' → ').
Related
Central tracking issue: ClickHouse/integrations-ai-playground#17
Bug: parsing escaped enum names
Enum (and Variant element) names can contain escaped single quotes (
\'), but the type string parser does not handle escape sequences in quoted strings.Affected code
clickhouse/types/type_parser.cpp,TypeParser::NextToken(), thecase '\''branch. There is even an existing TODO comment acknowledging the gap:// TODO (nemkov): handle escaping ?When the tokenizer scans for the closing
'it does not skip over\'sequences, so a name like'val\'ue'would be split at the backslash-escaped quote, returning a truncated/incorrect token.Example
A query such as:
returns a
Varianttype whose element type string contains single-quoted sub-types. When the client tries to parse the returned column type the tokenizer misreads the quoted segment.Expected behaviour
The parser should treat
\'inside a quoted string as an escaped single quote (part of the name), not as the closing delimiter. The stored value should also have the backslash removed (i.e.\'→').Related
Central tracking issue: ClickHouse/integrations-ai-playground#17