From e56e4606a66cffb6ed0fe6545c77900aa7969aa2 Mon Sep 17 00:00:00 2001 From: kenjis Date: Sat, 11 Nov 2023 21:37:59 +0900 Subject: [PATCH 1/7] test: add test for baseURL with subfolder --- tests/system/CommonFunctionsTest.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/system/CommonFunctionsTest.php b/tests/system/CommonFunctionsTest.php index 228a24e9a26f..a097cb2a81a0 100644 --- a/tests/system/CommonFunctionsTest.php +++ b/tests/system/CommonFunctionsTest.php @@ -612,6 +612,7 @@ public function testViewNotSaveData(): void public function testForceHttpsNullRequestAndResponse(): void { $this->assertNull(Services::response()->header('Location')); + Services::response()->setCookie('force', 'cookie'); Services::response()->setHeader('Force', 'header'); Services::response()->setBody('default body'); @@ -634,6 +635,25 @@ public function testForceHttpsNullRequestAndResponse(): void force_https(); } + public function testForceHttpsWithBaseUrlSubFolder(): void + { + $config = config(App::class); + $config->baseURL = 'https://example.jp/codeIgniter/'; + $uri = new SiteURI($config, 'en/home?foo=bar'); + $request = new IncomingRequest($config, $uri, '', new UserAgent()); + Services::injectMock('request', $request); + + try { + force_https(); + } catch (Exception $e) { + $this->assertInstanceOf(RedirectException::class, $e); + $this->assertSame( + 'https://example.jp/codeIgniter/index.php/en/home?foo=bar', + $e->getResponse()->header('Location')->getValue() + ); + } + } + /** * @dataProvider provideCleanPathActuallyCleaningThePaths * From d59fdaad5ab207d61fff9c0c4a98141c730b6af3 Mon Sep 17 00:00:00 2001 From: kenjis Date: Sun, 12 Nov 2023 19:59:39 +0900 Subject: [PATCH 2/7] fix: force_https() redirects to wrong URL --- system/Common.php | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/system/Common.php b/system/Common.php index 2d876564846e..451e6c601a63 100644 --- a/system/Common.php +++ b/system/Common.php @@ -502,27 +502,11 @@ function force_https( Services::session()->regenerate(); // @codeCoverageIgnore } - $baseURL = config(App::class)->baseURL; - - if (strpos($baseURL, 'https://') === 0) { - $authority = substr($baseURL, strlen('https://')); - } elseif (strpos($baseURL, 'http://') === 0) { - $authority = substr($baseURL, strlen('http://')); - } else { - $authority = $baseURL; - } - - $uri = URI::createURIString( - 'https', - $authority, - $request->getUri()->getPath(), // Absolute URIs should use a "/" for an empty path - $request->getUri()->getQuery(), - $request->getUri()->getFragment() - ); + $uri = $request->getUri()->withScheme('https'); // Set an HSTS header $response->setHeader('Strict-Transport-Security', 'max-age=' . $duration) - ->redirect($uri) + ->redirect((string) $uri) ->setStatusCode(307) ->setBody('') ->getCookieStore() From b25ff87a8e748807863d11256b508170e9cc9fd4 Mon Sep 17 00:00:00 2001 From: kenjis Date: Tue, 14 Nov 2023 13:14:46 +0900 Subject: [PATCH 3/7] docs: add @phpstan-param --- system/View/RendererInterface.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/system/View/RendererInterface.php b/system/View/RendererInterface.php index 409a5a76d3ba..a0f093b67326 100644 --- a/system/View/RendererInterface.php +++ b/system/View/RendererInterface.php @@ -46,6 +46,7 @@ public function renderString(string $view, ?array $options = null, bool $saveDat * * @param string $context The context to escape it for: html, css, js, url * If 'raw', no escaping will happen + * @phpstan-param null|'html'|'js'|'css'|'url'|'attr'|'raw' $context * * @return RendererInterface */ @@ -57,6 +58,7 @@ public function setData(array $data = [], ?string $context = null); * @param mixed $value * @param string $context The context to escape it for: html, css, js, url * If 'raw' no escaping will happen + * @phpstan-param null|'html'|'js'|'css'|'url'|'attr'|'raw' $context * * @return RendererInterface */ From 8fbeb9364be142060a9a0d1a57f2444fc21836b2 Mon Sep 17 00:00:00 2001 From: kenjis Date: Tue, 14 Nov 2023 13:15:41 +0900 Subject: [PATCH 4/7] refactor: replace empty() --- system/View/Cell.php | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/system/View/Cell.php b/system/View/Cell.php index f654e97a376d..de9bbe636e4e 100644 --- a/system/View/Cell.php +++ b/system/View/Cell.php @@ -84,11 +84,9 @@ public function render(string $library, $params = null, int $ttl = 0, ?string $c $params = $this->prepareParams($params); // Is the output cached? - $cacheName = ! empty($cacheName) - ? $cacheName - : str_replace(['\\', '/'], '', $class) . $method . md5(serialize($params)); + $cacheName ??= str_replace(['\\', '/'], '', $class) . $method . md5(serialize($params)); - if (! empty($this->cache) && $output = $this->cache->get($cacheName)) { + if ($output = $this->cache->get($cacheName)) { return $output; } @@ -105,7 +103,7 @@ public function render(string $library, $params = null, int $ttl = 0, ?string $c : $this->renderSimpleClass($instance, $method, $params, $class); // Can we cache it? - if (! empty($this->cache) && $ttl !== 0) { + if ($ttl !== 0) { $this->cache->save($cacheName, $output, $ttl); } @@ -119,11 +117,14 @@ public function render(string $library, $params = null, int $ttl = 0, ?string $c * * @param array|string|null $params * - * @return array|null + * @return array */ public function prepareParams($params) { - if (empty($params) || (! is_string($params) && ! is_array($params))) { + if ( + ($params === null || $params === '' || $params === []) + || (! is_string($params) && ! is_array($params)) + ) { return []; } @@ -139,7 +140,7 @@ public function prepareParams($params) unset($separator); foreach ($params as $p) { - if (! empty($p)) { + if ($p !== '') { [$key, $val] = explode('=', $p); $newParams[trim($key)] = trim($val, ', '); @@ -175,7 +176,7 @@ protected function determineClass(string $library): array [$class, $method] = explode(':', $library); - if (empty($class)) { + if ($class === '') { throw ViewException::forNoCellClass(); } @@ -187,7 +188,7 @@ protected function determineClass(string $library): array throw ViewException::forInvalidCellClass($class); } - if (empty($method)) { + if ($method === '') { $method = 'index'; } @@ -274,7 +275,7 @@ final protected function renderSimpleClass($instance, string $method, array $par $refParams = $refMethod->getParameters(); if ($paramCount === 0) { - if (! empty($params)) { + if ($params !== []) { throw ViewException::forMissingCellParameters($class, $method); } From 6ddc920f0a368b1157bfae16c2ec6353900943ce Mon Sep 17 00:00:00 2001 From: kenjis Date: Tue, 14 Nov 2023 13:15:58 +0900 Subject: [PATCH 5/7] chore: phpstan-baseline.php --- phpstan-baseline.php | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/phpstan-baseline.php b/phpstan-baseline.php index beb2d85a4d84..7f9182eeeeda 100644 --- a/phpstan-baseline.php +++ b/phpstan-baseline.php @@ -3951,16 +3951,6 @@ 'count' => 1, 'path' => __DIR__ . '/system/View/Cell.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', - 'count' => 8, - 'path' => __DIR__ . '/system/View/Cell.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Property CodeIgniter\\\\View\\\\Cell\\:\\:\\$cache \\(CodeIgniter\\\\Cache\\\\CacheInterface\\) in empty\\(\\) is not falsy\\.$#', - 'count' => 2, - 'path' => __DIR__ . '/system/View/Cell.php', -]; $ignoreErrors[] = [ 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', 'count' => 1, @@ -4006,16 +3996,6 @@ 'count' => 3, 'path' => __DIR__ . '/system/View/View.php', ]; -$ignoreErrors[] = [ - '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\\(\\)$#', - 'count' => 1, - 'path' => __DIR__ . '/system/View/View.php', -]; -$ignoreErrors[] = [ - '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\\(\\)$#', - 'count' => 1, - 'path' => __DIR__ . '/system/View/View.php', -]; $ignoreErrors[] = [ 'message' => '#^Short ternary operator is not allowed\\. Use null coalesce operator if applicable or consider using long ternary\\.$#', 'count' => 2, From f364cb8a5a0ad7f9a146fbd8174f13edb942ce6b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 14 Nov 2023 15:06:55 +0000 Subject: [PATCH 6/7] chore(deps): bump actions/github-script from 6 to 7 Bumps [actions/github-script](https://github.com/actions/github-script) from 6 to 7. - [Release notes](https://github.com/actions/github-script/releases) - [Commits](https://github.com/actions/github-script/compare/v6...v7) --- updated-dependencies: - dependency-name: actions/github-script dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/deploy-distributables.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploy-distributables.yml b/.github/workflows/deploy-distributables.yml index 3d4b31f289e6..f28a62544fa5 100644 --- a/.github/workflows/deploy-distributables.yml +++ b/.github/workflows/deploy-distributables.yml @@ -66,7 +66,7 @@ jobs: run: ./source/.github/scripts/deploy-framework ${GITHUB_WORKSPACE}/source ${GITHUB_WORKSPACE}/framework ${GITHUB_REF##*/} - name: Release - uses: actions/github-script@v6 + uses: actions/github-script@v7 with: github-token: ${{secrets.ACCESS_TOKEN}} script: | @@ -116,7 +116,7 @@ jobs: run: ./source/.github/scripts/deploy-appstarter ${GITHUB_WORKSPACE}/source ${GITHUB_WORKSPACE}/appstarter ${GITHUB_REF##*/} - name: Release - uses: actions/github-script@v6 + uses: actions/github-script@v7 with: github-token: ${{secrets.ACCESS_TOKEN}} script: | @@ -172,7 +172,7 @@ jobs: run: ./source/.github/scripts/deploy-userguide ${GITHUB_WORKSPACE}/source ${GITHUB_WORKSPACE}/userguide ${GITHUB_REF##*/} - name: Release - uses: actions/github-script@v6 + uses: actions/github-script@v7 with: github-token: ${{secrets.ACCESS_TOKEN}} script: | From 0f9b27b57d4a4a560719486f850ff1653e2ce64b Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 16 Nov 2023 09:09:33 +0900 Subject: [PATCH 7/7] docs: update outdated sample code --- user_guide_src/source/helpers/filesystem_helper/010.php | 2 +- user_guide_src/source/helpers/filesystem_helper/011.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/user_guide_src/source/helpers/filesystem_helper/010.php b/user_guide_src/source/helpers/filesystem_helper/010.php index 51db194b6d63..3b88fda2a77b 100644 --- a/user_guide_src/source/helpers/filesystem_helper/010.php +++ b/user_guide_src/source/helpers/filesystem_helper/010.php @@ -1,3 +1,3 @@