Skip to content

Commit 9f73fa0

Browse files
committed
Merge remote-tracking branch 'upstream/develop' into 4.4
Conflicts: system/Debug/Exceptions.php
2 parents 2923328 + 3bbe1da commit 9f73fa0

File tree

23 files changed

+180
-38
lines changed

23 files changed

+180
-38
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
### Breaking Changes
77

88
* fix: base_url() removes trailing slash in baseURL by @kenjis in https://github.com/codeigniter4/CodeIgniter4/pull/7200
9+
* fix: remove parameter $relative in `uri_string()` by @kenjis in https://github.com/codeigniter4/CodeIgniter4/pull/7135
910

1011
### Fixed Bugs
1112

@@ -14,7 +15,6 @@
1415
* fix: remove `All` from `Options All -Indexes` in .htaccess by @sba in https://github.com/codeigniter4/CodeIgniter4/pull/7093
1516
* fix: bug on stuck content-type header in Feature Testing by @baycik in https://github.com/codeigniter4/CodeIgniter4/pull/7112
1617
* fix: ordering `Validation` show error by call `setRule()` by @ddevsr in https://github.com/codeigniter4/CodeIgniter4/pull/7149
17-
* fix: remove parameter $relative in `uri_string()` by @kenjis in https://github.com/codeigniter4/CodeIgniter4/pull/7135
1818
* fix: [QueryBuilder] where() generates incorrect SQL when using RawSql by @sclubricants in https://github.com/codeigniter4/CodeIgniter4/pull/7147
1919
* fix: [QueryBuilder] RawSql passed to set() disappears without error by @kenjis in https://github.com/codeigniter4/CodeIgniter4/pull/7148
2020
* fix: [Parser] local_currency causes "Passing null to parameter" by @kenjis in https://github.com/codeigniter4/CodeIgniter4/pull/7157

system/API/ResponseTrait.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,10 @@ protected function respond($data = null, ?int $status = null, string $message =
9292
if ($data === null && $status === null) {
9393
$status = 404;
9494
$output = null;
95+
$this->format($data);
9596
} elseif ($data === null && is_numeric($status)) {
9697
$output = null;
98+
$this->format($data);
9799
} else {
98100
$status = empty($status) ? 200 : $status;
99101
$output = $this->format($data);

system/Cache/Handlers/FileHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ protected function getDirFileInfo(string $sourceDir, bool $topLevelOnly = true,
346346
while (false !== ($file = readdir($fp))) {
347347
if (is_dir($sourceDir . $file) && $file[0] !== '.' && $topLevelOnly === false) {
348348
$this->getDirFileInfo($sourceDir . $file . DIRECTORY_SEPARATOR, $topLevelOnly, true);
349-
} elseif ($file[0] !== '.') {
349+
} elseif (! is_dir($sourceDir . $file) && $file[0] !== '.') {
350350
$_filedata[$file] = $this->getFileInfo($sourceDir . $file);
351351
$_filedata[$file]['relative_path'] = $relativePath;
352352
}

system/Commands/Database/MigrateRollback.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class MigrateRollback extends BaseCommand
5757
* @var array
5858
*/
5959
protected $options = [
60-
'-b' => 'Specify a batch to roll back to; e.g. "3" to return to batch #3 or "-2" to roll back twice',
60+
'-b' => 'Specify a batch to roll back to; e.g. "3" to return to batch #3',
6161
'-g' => 'Set database group',
6262
'-f' => 'Force command - this option allows you to bypass the confirmation question when running this command in a production environment',
6363
];

system/Debug/Exceptions.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ public function exceptionHandler(Throwable $exception)
123123
$this->request = Services::request();
124124
$this->response = Services::response();
125125

126+
// Get the first exception.
127+
while ($prevException = $exception->getPrevious()) {
128+
$exception = $prevException;
129+
}
130+
126131
if ($this->config->log === true && ! in_array($statusCode, $this->config->ignoreCodes, true)) {
127132
log_message('critical', "{message}\nin {exFile} on line {exLine}.\n{trace}", [
128133
'message' => $exception->getMessage(),

system/Helpers/text_helper.php

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ function random_string(string $type = 'alnum', int $len = 8): string
559559
break;
560560
}
561561

562-
return substr(str_shuffle(str_repeat($pool, (int) ceil($len / strlen($pool)))), 0, $len);
562+
return _from_random($len, $pool);
563563

564564
case 'numeric':
565565
$max = 10 ** $len - 1;
@@ -587,6 +587,69 @@ function random_string(string $type = 'alnum', int $len = 8): string
587587
}
588588
}
589589

590+
if (! function_exists('_from_random')) {
591+
/**
592+
* The following function was derived from code of Symfony (v6.2.7 - 2023-02-28)
593+
* https://github.com/symfony/symfony/blob/80cac46a31d4561804c17d101591a4f59e6db3a2/src/Symfony/Component/String/ByteString.php#L45
594+
* Code subject to the MIT license (https://github.com/symfony/symfony/blob/v6.2.7/LICENSE).
595+
* Copyright (c) 2004-present Fabien Potencier
596+
*
597+
* The following method was derived from code of the Hack Standard Library (v4.40 - 2020-05-03)
598+
* https://github.com/hhvm/hsl/blob/80a42c02f036f72a42f0415e80d6b847f4bf62d5/src/random/private.php#L16
599+
* Code subject to the MIT license (https://github.com/hhvm/hsl/blob/master/LICENSE).
600+
* Copyright (c) 2004-2020, Facebook, Inc. (https://www.facebook.com/)
601+
*
602+
* @internal Outside the framework this should not be used directly.
603+
*/
604+
function _from_random(int $length, string $pool): string
605+
{
606+
if ($length <= 0) {
607+
throw new InvalidArgumentException(
608+
sprintf('A strictly positive length is expected, "%d" given.', $length)
609+
);
610+
}
611+
612+
$poolSize = \strlen($pool);
613+
$bits = (int) ceil(log($poolSize, 2.0));
614+
if ($bits <= 0 || $bits > 56) {
615+
throw new InvalidArgumentException(
616+
'The length of the alphabet must in the [2^1, 2^56] range.'
617+
);
618+
}
619+
620+
$string = '';
621+
622+
while ($length > 0) {
623+
$urandomLength = (int) ceil(2 * $length * $bits / 8.0);
624+
$data = random_bytes($urandomLength);
625+
$unpackedData = 0;
626+
$unpackedBits = 0;
627+
628+
for ($i = 0; $i < $urandomLength && $length > 0; $i++) {
629+
// Unpack 8 bits
630+
$unpackedData = ($unpackedData << 8) | \ord($data[$i]);
631+
$unpackedBits += 8;
632+
633+
// While we have enough bits to select a character from the alphabet, keep
634+
// consuming the random data
635+
for (; $unpackedBits >= $bits && $length > 0; $unpackedBits -= $bits) {
636+
$index = ($unpackedData & ((1 << $bits) - 1));
637+
$unpackedData >>= $bits;
638+
// Unfortunately, the alphabet size is not necessarily a power of two.
639+
// Worst case, it is 2^k + 1, which means we need (k+1) bits and we
640+
// have around a 50% chance of missing as k gets larger
641+
if ($index < $poolSize) {
642+
$string .= $pool[$index];
643+
$length--;
644+
}
645+
}
646+
}
647+
}
648+
649+
return $string;
650+
}
651+
}
652+
590653
if (! function_exists('increment_string')) {
591654
/**
592655
* Add's _1 to a string or increment the ending number to allow _2, _3, etc

system/Helpers/url_helper.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,20 @@ function site_url($relativePath = '', ?string $scheme = null, ?App $config = nul
117117
{
118118
$uri = _get_uri($relativePath, $config);
119119

120-
return URI::createURIString(
120+
$uriString = URI::createURIString(
121121
$scheme ?? $uri->getScheme(),
122122
$uri->getAuthority(),
123123
$uri->getPath(),
124124
$uri->getQuery(),
125125
$uri->getFragment()
126126
);
127+
128+
// For protocol-relative links
129+
if ($scheme === '') {
130+
$uriString = '//' . $uriString;
131+
}
132+
133+
return $uriString;
127134
}
128135
}
129136

system/ThirdParty/Kint/Zval/Representation/SplFileInfoRepresentation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function __construct(SplFileInfo $fileInfo)
5757
$this->path = $fileInfo->getPathname();
5858

5959
try {
60-
if ($fileInfo->getRealPath()) {
60+
if (\strlen($this->path) && $fileInfo->getRealPath()) {
6161
$this->perms = $fileInfo->getPerms();
6262
$this->size = $fileInfo->getSize();
6363
$this->owner = $fileInfo->getOwner();

tests/system/API/ResponseTraitTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ public function testNoContent()
341341

342342
$this->invoke($controller, 'respondNoContent', ['']);
343343

344+
$this->assertStringStartsWith('application/json', $this->response->getHeaderLine('Content-Type'));
344345
$this->assertSame('No Content', $this->response->getReason());
345346
$this->assertSame(204, $this->response->getStatusCode());
346347
}

tests/system/Helpers/URLHelper/SiteUrlTest.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,21 @@ public function configProvider()
304304
];
305305
}
306306

307-
// base_url
307+
public function testSiteURLWithEmptyStringScheme()
308+
{
309+
$this->config->baseURL = 'http://example.com/';
310+
$this->config->indexPage = 'index.php';
311+
$this->config->forceGlobalSecureRequests = false;
312+
313+
$this->assertSame(
314+
'//example.com/index.php/test',
315+
site_url('test', '', $this->config)
316+
);
317+
$this->assertSame(
318+
'//example.com/img/test.jpg',
319+
base_url('img/test.jpg', '')
320+
);
321+
}
308322

309323
/**
310324
* These tests are only really relevant to show that base_url()

0 commit comments

Comments
 (0)