Skip to content

Commit 422bb9a

Browse files
committed
fix: avoid double-prefixing in BaseConnection::callFunction()
1 parent a5fc034 commit 422bb9a

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

system/Database/BaseConnection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1508,7 +1508,7 @@ public function callFunction(string $functionName, ...$params): bool
15081508
{
15091509
$driver = $this->getDriverFunctionPrefix();
15101510

1511-
if (! str_contains($driver, $functionName)) {
1511+
if (! str_starts_with($functionName, $driver)) {
15121512
$functionName = $driver . $functionName;
15131513
}
15141514

tests/system/Database/BaseConnectionTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,4 +345,28 @@ public static function provideEscapeIdentifier(): iterable
345345
'with dots' => ['com.sitedb.web', '"com.sitedb.web"'],
346346
];
347347
}
348+
349+
public function testCallFunctionDoesNotDoublePrefixAlreadyPrefixedName(): void
350+
{
351+
$db = new class ($this->options) extends MockConnection {
352+
protected function getDriverFunctionPrefix(): string
353+
{
354+
return 'str_';
355+
}
356+
};
357+
358+
$this->assertTrue($db->callFunction('str_contains', 'CodeIgniter', 'Ignite'));
359+
}
360+
361+
public function testCallFunctionPrefixesUnprefixedName(): void
362+
{
363+
$db = new class ($this->options) extends MockConnection {
364+
protected function getDriverFunctionPrefix(): string
365+
{
366+
return 'str_';
367+
}
368+
};
369+
370+
$this->assertTrue($db->callFunction('contains', 'CodeIgniter', 'Ignite'));
371+
}
348372
}

user_guide_src/source/changelogs/v4.7.1.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Bugs Fixed
4040

4141
- **ContentSecurityPolicy:** Fixed a bug where custom CSP tags were not removed from generated HTML when CSP was disabled. The method now ensures that all custom CSP tags are removed from the generated HTML.
4242
- **ContentSecurityPolicy:** Fixed a bug where ``generateNonces()`` produces corrupted JSON responses by replacing CSP nonce placeholders with unescaped double quotes. The method now automatically JSON-escapes nonce attributes when the response Content-Type is JSON.
43+
- **Database:** Fixed a bug where ``BaseConnection::callFunction()`` could double-prefix already-prefixed function names.
4344
- **Model:** Fixed a bug where ``BaseModel::updateBatch()`` threw an exception when ``updateOnlyChanged`` was ``true`` and the index field value did not change.
4445
- **Session:** Fixed a bug in ``MemcachedHandler`` where the constructor incorrectly threw an exception when ``savePath`` was not empty.
4546
- **Toolbar:** Fixed a bug where the standalone toolbar page loaded from ``?debugbar_time=...`` was not interactive.

0 commit comments

Comments
 (0)