Skip to content

Commit

Permalink
test(param-value-converter-registry): cover string escaping (#292)
Browse files Browse the repository at this point in the history
  • Loading branch information
simPod authored Jan 30, 2025
1 parent d8072cd commit a4d85be
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/Param/ParamValueConverterRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use DateTimeInterface;
use Psr\Http\Message\StreamInterface;
use SimPod\ClickHouseClient\Exception\UnsupportedParamType;
use SimPod\ClickHouseClient\Sql\Escaper;
use SimPod\ClickHouseClient\Sql\Type;

use function array_keys;
Expand All @@ -20,7 +21,6 @@
use function is_string;
use function json_encode;
use function sprintf;
use function str_replace;
use function strlen;
use function strtolower;
use function trim;
Expand Down Expand Up @@ -95,8 +95,8 @@ public function __construct(array $registry = [])
'datetime' => self::dateTimeConverter(),
'datetime32' => self::dateTimeConverter(),
'datetime64' => static fn (DateTimeInterface|string|int|float $value) => $value instanceof DateTimeInterface
? $value->format('U.u')
: $value,
? $value->format('U.u')
: $value,

'Dynamic' => self::noopConverter(),
'Variant' => self::noopConverter(),
Expand Down Expand Up @@ -246,7 +246,7 @@ private static function stringConverter(): Closure
string $value,
Type|string|null $type = null,
bool $nested = false,
) => $nested ? '\'' . str_replace("'", "\'", $value) . '\'' : $value;
) => $nested ? "'" . Escaper::escape($value) . "'" : $value;
}

private static function noopConverter(): Closure
Expand Down
2 changes: 1 addition & 1 deletion tests/Param/ParamValueConverterRegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public static function providerConvert(): Generator
{
yield 'Array' => ['Array(String)', "['foo','bar']", "['foo','bar']"];
yield 'Array LC' => ['Array(LowCardinality(String))', "['foo','bar']", "['foo','bar']"];
yield 'Array (array)' => ['Array(String)', ['foo', 'bar'], "['foo','bar']"];
yield 'Array (array)' => ['Array(String)', ['foo', 'bar', "baz'"], "['foo','bar','baz\\'']"];
yield 'Array Tuple' => ['Array(Tuple(String, String))', [['foo', 'bar']], "[('foo','bar')]"];
yield 'Array Tuple Complex' => [
'Array(Tuple(Tuple(UInt32, UUID), String))',
Expand Down

0 comments on commit a4d85be

Please sign in to comment.