Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelogs/v4.7.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Release Date: Unreleased

## Bugs Fixed

- **Database:** Fixed a bug where `SQLSRV\Builder::_upsertBatch()` concatenated `$table` unescaped into `Object_ID()`, causing syntax errors for table names with quotes or special characters.
- **Security:** Fixed a bug where `Security::__construct()` threw a `TypeError` when the CSRF cookie was an array, causing an HTTP 500 response for affected requests.
- **Worker Mode:** Fixed a bug where every request that ended with an uncaught exception, including a `404 Page Not Found` without a 404 override, called `exit()` in the exception handler. This ended the worker script, so FrankenPHP booted a new one, and the worker loop skipped its cleanup after the request. The exception handler now returns to the worker loop.

Expand Down
2 changes: 1 addition & 1 deletion system/Database/SQLSRV/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ protected function _upsertBatch(string $table, array $keys, array $values): stri
$constraints = $this->QBOptions['constraints'] ?? [];

$tableIdentity = $this->QBOptions['tableIdentity'] ?? '';
$sql = "SELECT name from syscolumns where id = Object_ID('" . $table . "') and colstat = 1";
$sql = 'SELECT name from syscolumns where id = Object_ID(' . $this->db->escape($table) . ') and colstat = 1';
if (($query = $this->db->query($sql)) === false) {
throw new DatabaseException('Failed to get table identity');
}
Expand Down
46 changes: 46 additions & 0 deletions tests/system/Database/Builder/SQLSRVBuilderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

/**
* This file is part of CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <admin@codeigniter.com>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/

namespace CodeIgniter\Database\Builder;

use CodeIgniter\Database\SQLSRV\Builder;
use CodeIgniter\Test\CIUnitTestCase;
use CodeIgniter\Test\Mock\MockConnection;
use PHPUnit\Framework\Attributes\Group;
use ReflectionMethod;
use Throwable;

/**
* @internal
*/
#[Group('Others')]
final class SQLSRVBuilderTest extends CIUnitTestCase
{
public function testUpsertBatchEscapesTableNameInObjectID(): void
{
$db = new MockConnection(['DBDriver' => 'SQLSRV']);
$builder = new Builder("user's", $db);

$method = new ReflectionMethod($builder, '_upsertBatch');

try {
$method->invoke($builder, "user's", ['id', 'name'], [['1', 'Alice']]);
} catch (Throwable) {
}

$this->assertSame(
"SELECT name from syscolumns where id = Object_ID('user''s') and colstat = 1",
(string) $db->getLastQuery(),
);
}
}
Loading