Skip to content

Commit a4d85be

Browse files
authored
test(param-value-converter-registry): cover string escaping (#292)
1 parent d8072cd commit a4d85be

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/Param/ParamValueConverterRegistry.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use DateTimeInterface;
99
use Psr\Http\Message\StreamInterface;
1010
use SimPod\ClickHouseClient\Exception\UnsupportedParamType;
11+
use SimPod\ClickHouseClient\Sql\Escaper;
1112
use SimPod\ClickHouseClient\Sql\Type;
1213

1314
use function array_keys;
@@ -20,7 +21,6 @@
2021
use function is_string;
2122
use function json_encode;
2223
use function sprintf;
23-
use function str_replace;
2424
use function strlen;
2525
use function strtolower;
2626
use function trim;
@@ -95,8 +95,8 @@ public function __construct(array $registry = [])
9595
'datetime' => self::dateTimeConverter(),
9696
'datetime32' => self::dateTimeConverter(),
9797
'datetime64' => static fn (DateTimeInterface|string|int|float $value) => $value instanceof DateTimeInterface
98-
? $value->format('U.u')
99-
: $value,
98+
? $value->format('U.u')
99+
: $value,
100100

101101
'Dynamic' => self::noopConverter(),
102102
'Variant' => self::noopConverter(),
@@ -246,7 +246,7 @@ private static function stringConverter(): Closure
246246
string $value,
247247
Type|string|null $type = null,
248248
bool $nested = false,
249-
) => $nested ? '\'' . str_replace("'", "\'", $value) . '\'' : $value;
249+
) => $nested ? "'" . Escaper::escape($value) . "'" : $value;
250250
}
251251

252252
private static function noopConverter(): Closure

tests/Param/ParamValueConverterRegistryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public static function providerConvert(): Generator
117117
{
118118
yield 'Array' => ['Array(String)', "['foo','bar']", "['foo','bar']"];
119119
yield 'Array LC' => ['Array(LowCardinality(String))', "['foo','bar']", "['foo','bar']"];
120-
yield 'Array (array)' => ['Array(String)', ['foo', 'bar'], "['foo','bar']"];
120+
yield 'Array (array)' => ['Array(String)', ['foo', 'bar', "baz'"], "['foo','bar','baz\\'']"];
121121
yield 'Array Tuple' => ['Array(Tuple(String, String))', [['foo', 'bar']], "[('foo','bar')]"];
122122
yield 'Array Tuple Complex' => [
123123
'Array(Tuple(Tuple(UInt32, UUID), String))',

0 commit comments

Comments
 (0)