Skip to content
Merged
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 @@ -20,6 +20,7 @@ Release Date: Unreleased
- **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.
- **Database:** Fixed a bug where `SQLSRV\Forge::_alterTable()` interpolated table and column names without escaping in default constraint lookups.
- **Database:** Fixed a bug where `SQLite3\Table::dropIndexes()` used single-quoted string literals instead of escaped identifiers in `DROP INDEX IF EXISTS`, causing syntax errors on index names containing quotes or special characters.
- **HTTP:** Fixed a bug where query-string based routing truncated additional query parameters in `SiteURIFactory::parseRequestURI()` due to incorrect array index access.
- **HTTP:** Fixed a bug where `UploadedFile::move()` and `UploadedFile::store()` on Windows could store a file under a different name than `getName()` reported, or write its contents to an NTFS alternate data stream. Filenames ending in a period or space or containing a colon are now rejected, including explicitly supplied names.
- **Images:** Fixed a bug in `ImageMagickHandler::save()` where saving without an extension or with an unsupported extension threw an `ImagickException` instead of falling back to the image's format.
- **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.
Expand Down
2 changes: 1 addition & 1 deletion system/HTTP/SiteURIFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ private function parseRequestURI(): string
if (trim($path, '/') === '' && str_starts_with($query, '/')) {
$parts = explode('?', $query, 2);
$path = $parts[0];
$newQuery = $query[1] ?? '';
$newQuery = $parts[1] ?? '';

$this->superglobals->setServer('QUERY_STRING', $newQuery);
} else {
Expand Down
67 changes: 67 additions & 0 deletions tests/system/HTTP/SiteURIFactoryDetectRoutePathTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,73 @@ public function testQueryStringWithQueryString(): void
$this->assertSame(['code' => 'good'], $_GET);
}

public function testRequestURIWithQueryBasedRoutingAndQueryParameters(): void
{
// /index.php?/ci/woot?code=good#pos
service('superglobals')
->setServer('REQUEST_URI', '/index.php?/ci/woot?code=good')
->setServer('SCRIPT_NAME', '/index.php')
->setGet('/ci/woot?code', 'good');

$factory = $this->createSiteURIFactory(service('superglobals')->getServerArray());

$expected = 'ci/woot';
$this->assertSame($expected, $factory->detectRoutePath('REQUEST_URI'));
$this->assertSame('code=good', $_SERVER['QUERY_STRING']); // @phpstan-ignore codeigniter.superglobalsOffsetAccess (checks the live superglobal, not the snapshot service)
$this->assertSame(['code' => 'good'], $_GET);
}

public function testRequestURIWithQueryBasedRoutingWithoutAdditionalQuery(): void
{
// /index.php?/ci/woot
service('superglobals')
->setServer('REQUEST_URI', '/index.php?/ci/woot')
->setServer('SCRIPT_NAME', '/index.php')
->setGet('/ci/woot', '');

$factory = $this->createSiteURIFactory(service('superglobals')->getServerArray());

$expected = 'ci/woot';
$this->assertSame($expected, $factory->detectRoutePath('REQUEST_URI'));
$this->assertSame('', $_SERVER['QUERY_STRING']); // @phpstan-ignore codeigniter.superglobalsOffsetAccess (checks the live superglobal, not the snapshot service)
$this->assertSame([], $_GET);
}

public function testRequestURIWithQueryBasedRoutingPreservesSubsequentQuestionMarks(): void
{
// /index.php?/ci/woot?redirect=/a?b=1
service('superglobals')
->setServer('REQUEST_URI', '/index.php?/ci/woot?redirect=/a?b=1')
->setServer('SCRIPT_NAME', '/index.php')
->setGet('/ci/woot?redirect', '/a?b=1');

$factory = $this->createSiteURIFactory(service('superglobals')->getServerArray());

$expected = 'ci/woot';
$this->assertSame($expected, $factory->detectRoutePath('REQUEST_URI'));
// Only the first '?' separates the path from the query string, so the
// remaining question marks must be kept inside the query string.
$this->assertSame('redirect=/a?b=1', $_SERVER['QUERY_STRING']); // @phpstan-ignore codeigniter.superglobalsOffsetAccess (checks the live superglobal, not the snapshot service)
$this->assertSame(['redirect' => '/a?b=1'], $_GET);
}

public function testRequestURIWithQueryBasedRoutingWithTrailingQuestionMark(): void
{
// /index.php?/ci/woot?
service('superglobals')
->setServer('REQUEST_URI', '/index.php?/ci/woot?')
->setServer('SCRIPT_NAME', '/index.php')
->setGet('/ci/woot?', '');

$factory = $this->createSiteURIFactory(service('superglobals')->getServerArray());

$expected = 'ci/woot';
$this->assertSame($expected, $factory->detectRoutePath('REQUEST_URI'));
// A trailing '?' keeps an empty query string, not the '?' itself.
$this->assertSame('', $_SERVER['QUERY_STRING']); // @phpstan-ignore codeigniter.superglobalsOffsetAccess (checks the live superglobal, not the snapshot service)
$this->assertSame([], $_GET);
}

public function testQueryStringRefreshesRequestWithoutOverwritingCustomValues(): void
{
if (! $this->effectiveRequestOrderIncludesGet()) {
Expand Down
Loading