Skip to content

Commit de116cc

Browse files
committed
Merge remote-tracking branch 'upstream/develop' into 4.5
2 parents 9e3839f + 46ac972 commit de116cc

File tree

8 files changed

+41
-54
lines changed

8 files changed

+41
-54
lines changed

.github/workflows/deploy-distributables.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ jobs:
6666
run: ./source/.github/scripts/deploy-framework ${GITHUB_WORKSPACE}/source ${GITHUB_WORKSPACE}/framework ${GITHUB_REF##*/}
6767

6868
- name: Release
69-
uses: actions/github-script@v6
69+
uses: actions/github-script@v7
7070
with:
7171
github-token: ${{secrets.ACCESS_TOKEN}}
7272
script: |
@@ -116,7 +116,7 @@ jobs:
116116
run: ./source/.github/scripts/deploy-appstarter ${GITHUB_WORKSPACE}/source ${GITHUB_WORKSPACE}/appstarter ${GITHUB_REF##*/}
117117

118118
- name: Release
119-
uses: actions/github-script@v6
119+
uses: actions/github-script@v7
120120
with:
121121
github-token: ${{secrets.ACCESS_TOKEN}}
122122
script: |
@@ -172,7 +172,7 @@ jobs:
172172
run: ./source/.github/scripts/deploy-userguide ${GITHUB_WORKSPACE}/source ${GITHUB_WORKSPACE}/userguide ${GITHUB_REF##*/}
173173

174174
- name: Release
175-
uses: actions/github-script@v6
175+
uses: actions/github-script@v7
176176
with:
177177
github-token: ${{secrets.ACCESS_TOKEN}}
178178
script: |

phpstan-baseline.php

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3711,16 +3711,6 @@
37113711
'count' => 1,
37123712
'path' => __DIR__ . '/system/View/Cell.php',
37133713
];
3714-
$ignoreErrors[] = [
3715-
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
3716-
'count' => 8,
3717-
'path' => __DIR__ . '/system/View/Cell.php',
3718-
];
3719-
$ignoreErrors[] = [
3720-
'message' => '#^Property CodeIgniter\\\\View\\\\Cell\\:\\:\\$cache \\(CodeIgniter\\\\Cache\\\\CacheInterface\\) in empty\\(\\) is not falsy\\.$#',
3721-
'count' => 2,
3722-
'path' => __DIR__ . '/system/View/Cell.php',
3723-
];
37243714
$ignoreErrors[] = [
37253715
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
37263716
'count' => 1,
@@ -3766,16 +3756,6 @@
37663756
'count' => 3,
37673757
'path' => __DIR__ . '/system/View/View.php',
37683758
];
3769-
$ignoreErrors[] = [
3770-
'message' => '#^Parameter \\#2 \\$context \\(\'attr\'\\|\'css\'\\|\'html\'\\|\'js\'\\|\'raw\'\\|\'url\'\\|null\\) of method CodeIgniter\\\\View\\\\View\\:\\:setData\\(\\) should be contravariant with parameter \\$context \\(string\\|null\\) of method CodeIgniter\\\\View\\\\RendererInterface\\:\\:setData\\(\\)$#',
3771-
'count' => 1,
3772-
'path' => __DIR__ . '/system/View/View.php',
3773-
];
3774-
$ignoreErrors[] = [
3775-
'message' => '#^Parameter \\#3 \\$context \\(\'attr\'\\|\'css\'\\|\'html\'\\|\'js\'\\|\'raw\'\\|\'url\'\\|null\\) of method CodeIgniter\\\\View\\\\View\\:\\:setVar\\(\\) should be contravariant with parameter \\$context \\(string\\|null\\) of method CodeIgniter\\\\View\\\\RendererInterface\\:\\:setVar\\(\\)$#',
3776-
'count' => 1,
3777-
'path' => __DIR__ . '/system/View/View.php',
3778-
];
37793759
$ignoreErrors[] = [
37803760
'message' => '#^Short ternary operator is not allowed\\. Use null coalesce operator if applicable or consider using long ternary\\.$#',
37813761
'count' => 2,

system/Common.php

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -502,27 +502,11 @@ function force_https(
502502
Services::session()->regenerate(); // @codeCoverageIgnore
503503
}
504504

505-
$baseURL = config(App::class)->baseURL;
506-
507-
if (strpos($baseURL, 'https://') === 0) {
508-
$authority = substr($baseURL, strlen('https://'));
509-
} elseif (strpos($baseURL, 'http://') === 0) {
510-
$authority = substr($baseURL, strlen('http://'));
511-
} else {
512-
$authority = $baseURL;
513-
}
514-
515-
$uri = URI::createURIString(
516-
'https',
517-
$authority,
518-
$request->getUri()->getPath(), // Absolute URIs should use a "/" for an empty path
519-
$request->getUri()->getQuery(),
520-
$request->getUri()->getFragment()
521-
);
505+
$uri = $request->getUri()->withScheme('https');
522506

523507
// Set an HSTS header
524508
$response->setHeader('Strict-Transport-Security', 'max-age=' . $duration)
525-
->redirect($uri)
509+
->redirect((string) $uri)
526510
->setStatusCode(307)
527511
->setBody('')
528512
->getCookieStore()

system/View/Cell.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,9 @@ public function render(string $library, $params = null, int $ttl = 0, ?string $c
8484
$params = $this->prepareParams($params);
8585

8686
// Is the output cached?
87-
$cacheName = ! empty($cacheName)
88-
? $cacheName
89-
: str_replace(['\\', '/'], '', $class) . $method . md5(serialize($params));
87+
$cacheName ??= str_replace(['\\', '/'], '', $class) . $method . md5(serialize($params));
9088

91-
if (! empty($this->cache) && $output = $this->cache->get($cacheName)) {
89+
if ($output = $this->cache->get($cacheName)) {
9290
return $output;
9391
}
9492

@@ -105,7 +103,7 @@ public function render(string $library, $params = null, int $ttl = 0, ?string $c
105103
: $this->renderSimpleClass($instance, $method, $params, $class);
106104

107105
// Can we cache it?
108-
if (! empty($this->cache) && $ttl !== 0) {
106+
if ($ttl !== 0) {
109107
$this->cache->save($cacheName, $output, $ttl);
110108
}
111109

@@ -119,11 +117,14 @@ public function render(string $library, $params = null, int $ttl = 0, ?string $c
119117
*
120118
* @param array|string|null $params
121119
*
122-
* @return array|null
120+
* @return array
123121
*/
124122
public function prepareParams($params)
125123
{
126-
if (empty($params) || (! is_string($params) && ! is_array($params))) {
124+
if (
125+
($params === null || $params === '' || $params === [])
126+
|| (! is_string($params) && ! is_array($params))
127+
) {
127128
return [];
128129
}
129130

@@ -139,7 +140,7 @@ public function prepareParams($params)
139140
unset($separator);
140141

141142
foreach ($params as $p) {
142-
if (! empty($p)) {
143+
if ($p !== '') {
143144
[$key, $val] = explode('=', $p);
144145

145146
$newParams[trim($key)] = trim($val, ', ');
@@ -175,7 +176,7 @@ protected function determineClass(string $library): array
175176

176177
[$class, $method] = explode(':', $library);
177178

178-
if (empty($class)) {
179+
if ($class === '') {
179180
throw ViewException::forNoCellClass();
180181
}
181182

@@ -187,7 +188,7 @@ protected function determineClass(string $library): array
187188
throw ViewException::forInvalidCellClass($class);
188189
}
189190

190-
if (empty($method)) {
191+
if ($method === '') {
191192
$method = 'index';
192193
}
193194

@@ -274,7 +275,7 @@ final protected function renderSimpleClass($instance, string $method, array $par
274275
$refParams = $refMethod->getParameters();
275276

276277
if ($paramCount === 0) {
277-
if (! empty($params)) {
278+
if ($params !== []) {
278279
throw ViewException::forMissingCellParameters($class, $method);
279280
}
280281

system/View/RendererInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public function renderString(string $view, ?array $options = null, bool $saveDat
4646
*
4747
* @param string $context The context to escape it for: html, css, js, url
4848
* If 'raw', no escaping will happen
49+
* @phpstan-param null|'html'|'js'|'css'|'url'|'attr'|'raw' $context
4950
*
5051
* @return RendererInterface
5152
*/
@@ -57,6 +58,7 @@ public function setData(array $data = [], ?string $context = null);
5758
* @param mixed $value
5859
* @param string $context The context to escape it for: html, css, js, url
5960
* If 'raw' no escaping will happen
61+
* @phpstan-param null|'html'|'js'|'css'|'url'|'attr'|'raw' $context
6062
*
6163
* @return RendererInterface
6264
*/

tests/system/CommonFunctionsTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,7 @@ public function testViewNotSaveData(): void
612612
public function testForceHttpsNullRequestAndResponse(): void
613613
{
614614
$this->assertNull(Services::response()->header('Location'));
615+
615616
Services::response()->setCookie('force', 'cookie');
616617
Services::response()->setHeader('Force', 'header');
617618
Services::response()->setBody('default body');
@@ -634,6 +635,25 @@ public function testForceHttpsNullRequestAndResponse(): void
634635
force_https();
635636
}
636637

638+
public function testForceHttpsWithBaseUrlSubFolder(): void
639+
{
640+
$config = config(App::class);
641+
$config->baseURL = 'https://example.jp/codeIgniter/';
642+
$uri = new SiteURI($config, 'en/home?foo=bar');
643+
$request = new IncomingRequest($config, $uri, '', new UserAgent());
644+
Services::injectMock('request', $request);
645+
646+
try {
647+
force_https();
648+
} catch (Exception $e) {
649+
$this->assertInstanceOf(RedirectException::class, $e);
650+
$this->assertSame(
651+
'https://example.jp/codeIgniter/index.php/en/home?foo=bar',
652+
$e->getResponse()->header('Location')->getValue()
653+
);
654+
}
655+
}
656+
637657
/**
638658
* @dataProvider provideCleanPathActuallyCleaningThePaths
639659
*
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<?php
22

3-
$controllers = get_filenames(APPPATH . 'controllers/');
3+
$controllers = get_filenames(APPPATH . 'Controllers/');
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<?php
22

3-
$models_info = get_dir_file_info(APPPATH . 'models/');
3+
$models_info = get_dir_file_info(APPPATH . 'Models/');

0 commit comments

Comments
 (0)