Skip to content

Commit 5b91fef

Browse files
Improves handling of {literal:...} in Db::quote()
Signed-off-by: Jon Stovell <jonstovell@gmail.com>
1 parent 494abbf commit 5b91fef

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

Sources/Db/APIs/MySQL.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,12 @@ public function quote(string $db_string, array $db_values, ?object $connection =
256256
if (str_contains($db_string, '{')) {
257257
// Do the quoting and escaping
258258
$db_string = preg_replace_callback(
259-
'~{([a-z_]+)(?::([a-zA-Z0-9_-]+))?}~',
259+
[
260+
// The literal type can have arbitrary content.
261+
'~{(literal):([^}]*)}~',
262+
// Everything else needs to be a key in $db_values.
263+
'~{([a-z_]+)(?::([a-zA-Z0-9_-]+))?}~',
264+
],
260265
fn($matches) => $this->replacement__callback($matches, $db_values, $connection ?? $this->connection),
261266
$db_string,
262267
);

Sources/Db/APIs/PostgreSQL.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,12 @@ public function quote(string $db_string, array $db_values, ?object $connection =
290290
if (str_contains($db_string, '{')) {
291291
// Do the quoting and escaping
292292
$db_string = preg_replace_callback(
293-
'~{([a-z_]+)(?::([a-zA-Z0-9_-]+))?}~',
293+
[
294+
// The literal type can have arbitrary content.
295+
'~{(literal):([^}]*)}~',
296+
// Everything else needs to be a key in $db_values.
297+
'~{([a-z_]+)(?::([a-zA-Z0-9_-]+))?}~',
298+
],
294299
fn($matches) => $this->replacement__callback($matches, $db_values, $connection ?? $this->connection),
295300
$db_string,
296301
);

0 commit comments

Comments
 (0)