-
Notifications
You must be signed in to change notification settings - Fork 71
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
Array(String) query parameters don't quote the strings #159
Comments
Thanks for the detailed investigation and report! You're correct, format_bind_value doesn't quote strings because ClickHouse doesn't expect them quoted when passed as the top level bind value, but apparently it does want them quoted in nested/contained values. In this instance I don't know what "sanitizing" would look like, I think ClickHouse itself handles safe substitution? In any case your solution looks good to me, and it would be great if you could submit a PR, otherwise I'll probably get to it in a week or so. |
Sanitizing means "what would happen if I pass Pretty sure that with the current code, from the python side we're sending 2 elements, but once we'll format it for passing to params, there will be 3 elements. Except if we already do a broad pass of escaping, but in that case, we'll escape Escaping needs to take place exactly once, and before we quote the string. We can't quote the string, mix it with other strings and then escape it. Whereas if, on string element, in In the tests, we need to check for inputs such as empty string, string consisting of just a single quote, 2 single quotes, and up to 5 single quotes, double quote, string beginning with a single quote, ending with a single quote, containing a single quote, empty array, array containing an int, array containing all the strings described above, array containing an array containing the strings above, other types on containers containing strings. |
Describe the bug
When using an
Array(String)
in server-side params the strings inside the array are sent unquoted, so the query crashesSteps to reproduce
client.query('SELECT {l:Array(String)}', parameters={"l": ["a"]}).result_rows
Expected behaviour
Returns
['a']
Code example
clickhouse-connect and/or ClickHouse server logs
Configuration
Environment
clickhouse-connect==0.5.16
ClickHouse server
CREATE TABLE
statements for tables involved:Additional info
It really looks like
format_bind_value
doesn't quote Strings, because when we use aString
at the top level we sendparam_x="something"
and notparam_x="'something'"
, but this logic only holds true at the top level.I think
format_bind_value
should have an optionaltop_level=True
parameter, when it calls itself recursively, it should call itself withtop_level=False
and when the input is a string, ifnot top_level
it should return'{input}'
(though with a bit of sanitazing to avoid injections)The text was updated successfully, but these errors were encountered: