Skip to content

Commit dcb5a20

Browse files
committed
fix: allow underscores in param names
1 parent d710fc4 commit dcb5a20

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/Client/Http/RequestFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function prepareSqlRequest(
8383
): RequestInterface {
8484
$request = $this->initRequest($requestSettings);
8585

86-
preg_match_all('~\{([a-zA-Z\d]+):([a-zA-Z\d ]+(\(.+\))?)}~', $sql, $matches);
86+
preg_match_all('~\{([a-zA-Z\d_]+):([a-zA-Z\d ]+(\(.+\))?)}~', $sql, $matches);
8787
if ($matches[0] === []) {
8888
$body = $this->streamFactory->createStream($sql);
8989
try {

tests/Client/Http/RequestFactoryTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace SimPod\ClickHouseClient\Tests\Client\Http;
66

7+
use DateTimeImmutable;
78
use Generator;
89
use Nyholm\Psr7\Factory\Psr17Factory;
910
use PHPUnit\Framework\Attributes\CoversClass;
@@ -66,4 +67,36 @@ public static function providerPrepareRequest(): Generator
6667
'?database=database&max_block_size=1',
6768
];
6869
}
70+
71+
public function testParamParsed(): void
72+
{
73+
$requestFactory = new RequestFactory(
74+
new ParamValueConverterRegistry(),
75+
new Psr17Factory(),
76+
new Psr17Factory(),
77+
);
78+
79+
$request = $requestFactory->prepareSqlRequest(
80+
'SELECT {p1:String}, {p_2:Date}',
81+
new RequestSettings(
82+
[],
83+
[],
84+
),
85+
new RequestOptions(
86+
[
87+
'p1' => 'value1',
88+
'p_2' => new DateTimeImmutable(),
89+
],
90+
),
91+
);
92+
93+
$body = $request->getBody()->__toString();
94+
self::assertStringContainsString('param_p1', $body);
95+
self::assertStringContainsString(
96+
<<<TEXT
97+
Content-Disposition: form-data; name="param_p_2"\r\nContent-Length: 10\r\n\r\n2025-01-23
98+
TEXT,
99+
$body,
100+
);
101+
}
69102
}

0 commit comments

Comments
 (0)