diff --git a/.github/carson.yml b/.github/carson.yml index 85bdc33aeca5..dcab95964d48 100644 --- a/.github/carson.yml +++ b/.github/carson.yml @@ -56,6 +56,13 @@ settings: Closing this issue: the description still does not follow the bug report template after {{days_until_close}} days. Please open a new issue using the [bug report form](https://github.com/codeigniter4/CodeIgniter4/issues/new?assignees=&labels=bug&projects=&template=bug_report.yml&title=Bug%3A+). For feature requests or support questions, please use the [forums](https://forum.codeigniter.com/forum-30.html). + - label: waiting for info + days_until_close: 14 + unlabel_on_response: true + close_message: |- + Closing this {{type}}: there has been no response for {{days_until_close}} days after more information was requested. + + If you can provide the requested details, leave a comment and a maintainer can reopen it. pr-title-linter: name: 'Carson / pr-title-linter' rules: diff --git a/.github/workflows/run-carson.yml b/.github/workflows/run-carson.yml index 1f404d1d2a33..2e8c46ba4a8e 100644 --- a/.github/workflows/run-carson.yml +++ b/.github/workflows/run-carson.yml @@ -14,6 +14,9 @@ on: - opened - edited - labeled + issue_comment: + types: + - created push: branches: - develop @@ -28,7 +31,7 @@ jobs: runs-on: ubuntu-24.04 steps: - name: Run Carson - uses: NexusPHP/carson@e4b2fde33f32c47455df218cf1765702c15c3b8b # v1.6.0 + uses: NexusPHP/carson@cb35604ab330c2e44dba673fcef712c78e75f858 # v1.7.0 with: app_id: ${{ secrets.CARSON_APP_ID }} private_key: ${{ secrets.CARSON_PRIVATE_KEY }} diff --git a/system/Database/Postgre/Connection.php b/system/Database/Postgre/Connection.php index a152b90aa539..6f6233d14b74 100644 --- a/system/Database/Postgre/Connection.php +++ b/system/Database/Postgre/Connection.php @@ -207,7 +207,13 @@ public function getVersion(): string protected function execute(string $sql) { try { - return pg_query($this->connID, $sql); + $result = pg_query($this->connID, $sql); + + if ($result === false && $this->DBDebug) { + throw new DatabaseException(pg_last_error($this->connID)); + } + + return $result; } catch (ErrorException $e) { $trace = array_slice($e->getTrace(), 2); // remove the call to error handler diff --git a/system/Database/ResultInterface.php b/system/Database/ResultInterface.php index 48de9f01c3d4..afe6ede83390 100644 --- a/system/Database/ResultInterface.php +++ b/system/Database/ResultInterface.php @@ -26,18 +26,22 @@ interface ResultInterface * individual data rows, which can be either an 'array', an * 'object', or a custom class name. * - * @param string $type The row type. Either 'array', 'object', or a class name to use + * @template T of object + * + * @param 'array'|'object'|class-string $type The row type. Either 'array', 'object', or a class name to use * - * @return ($type is 'array' ? list> : ($type is 'object' ? list : list)) + * @return ($type is 'array' ? list> : ($type is 'object' ? list : list)) */ public function getResult(string $type = 'object'): array; /** * Returns the results as an array of custom objects. * - * @param string $className The name of the class to use. + * @template T of object + * + * @param class-string $className The name of the class to use. * - * @return list + * @return list */ public function getCustomResultObject(string $className); @@ -102,7 +106,7 @@ public function getRowArray(int $n = 0); * * If row doesn't exist, returns null. * - * @return object|stdClass|null + * @return stdClass|null */ public function getRowObject(int $n = 0); diff --git a/system/HTTP/CLIRequest.php b/system/HTTP/CLIRequest.php index f1e98c50bf79..55c8b797b094 100644 --- a/system/HTTP/CLIRequest.php +++ b/system/HTTP/CLIRequest.php @@ -236,7 +236,7 @@ public function isCLI(): bool * @param int|null $filter A filter name to apply. * @param array|int|null $flags * - * @return array{}|null + * @return ($index is string ? null : array{}) */ public function getGet($index = null, $filter = null, $flags = null) { @@ -250,7 +250,7 @@ public function getGet($index = null, $filter = null, $flags = null) * @param int|null $filter A filter name to apply * @param array|int|null $flags * - * @return array{}|null + * @return ($index is string ? null : array{}) */ public function getPost($index = null, $filter = null, $flags = null) { @@ -264,7 +264,7 @@ public function getPost($index = null, $filter = null, $flags = null) * @param int|null $filter A filter name to apply * @param array|int|null $flags * - * @return array{}|null + * @return ($index is string ? null : array{}) */ public function getPostGet($index = null, $filter = null, $flags = null) { @@ -278,7 +278,7 @@ public function getPostGet($index = null, $filter = null, $flags = null) * @param int|null $filter A filter name to apply * @param array|int|null $flags * - * @return array{}|null + * @return ($index is string ? null : array{}) */ public function getGetPost($index = null, $filter = null, $flags = null) { @@ -292,7 +292,7 @@ public function getGetPost($index = null, $filter = null, $flags = null) * @param int|null $filter A filter name to be applied * @param mixed $flags * - * @return array{}|null + * @return ($index is string ? null : array{}) */ public function getCookie($index = null, $filter = null, $flags = null) { @@ -302,7 +302,7 @@ public function getCookie($index = null, $filter = null, $flags = null) /** * @param list|string|null $index * - * @return array{}|null + * @return ($index is string ? null : array{}) */ private function returnNullOrEmptyArray($index) { diff --git a/system/HTTP/IncomingRequest.php b/system/HTTP/IncomingRequest.php index 5eb029df8385..cc66e35f4ddc 100644 --- a/system/HTTP/IncomingRequest.php +++ b/system/HTTP/IncomingRequest.php @@ -403,7 +403,7 @@ public function getVar($index = null, $filter = null, $flags = null) * * @see http://php.net/manual/en/function.json-decode.php * - * @return array|bool|float|int|stdClass|null + * @return ($assoc is true ? array|bool|float|int|string|null : array|bool|float|int|stdClass|string|null) * * @throws HTTPException When the body is invalid as JSON. */ @@ -430,7 +430,7 @@ public function getJSON(bool $assoc = false, int $depth = 512, int $options = 0) * @param int|null $filter Filter Constant * @param array|int|null $flags Option * - * @return array|bool|float|int|stdClass|string|null + * @return ($assoc is true ? array|bool|float|int|string|null : array|bool|float|int|stdClass|string|null) */ public function getJsonVar($index = null, bool $assoc = false, ?int $filter = null, $flags = null) { diff --git a/system/Helpers/url_helper.php b/system/Helpers/url_helper.php index e43954909d65..c08187c6c40b 100644 --- a/system/Helpers/url_helper.php +++ b/system/Helpers/url_helper.php @@ -68,8 +68,8 @@ function base_url($relativePath = '', ?string $scheme = null): string * @param bool $returnObject True to return an object instead of a string * @param IncomingRequest|null $request A request to use when retrieving the path * - * @return string|URI When returning string, the query and fragment parts are removed. - * When returning URI, the query and fragment parts are preserved. + * @return ($returnObject is true ? URI : string) When returning string, the query and fragment parts are removed. + * When returning URI, the query and fragment parts are preserved. */ function current_url(bool $returnObject = false, ?IncomingRequest $request = null): string|URI { @@ -87,6 +87,8 @@ function current_url(bool $returnObject = false, ?IncomingRequest $request = nul * we first check in a saved session variable, if it exists, and use that. * If that's not available, however, we'll use a sanitized url from $_SERVER['HTTP_REFERER'] * which can be set by the user so is untrusted and not set by certain browsers/servers. + * + * @return ($returnObject is true ? URI : string) */ function previous_url(bool $returnObject = false): string|URI { diff --git a/system/Validation/CreditCardRules.php b/system/Validation/CreditCardRules.php index a31b303fcb86..0bc20f082123 100644 --- a/system/Validation/CreditCardRules.php +++ b/system/Validation/CreditCardRules.php @@ -199,8 +199,7 @@ public function valid_cc_number(?string $ccNumber, string $type): bool // Remove any spaces and dashes $ccNumber = str_replace([' ', '-'], '', $ccNumber); - // Non-numeric values cannot be a number...duh - if (! is_numeric($ccNumber)) { + if (! ctype_digit($ccNumber)) { return false; } diff --git a/tests/system/Database/Live/BadQueryTest.php b/tests/system/Database/Live/BadQueryTest.php index 8b842b21b930..587cabc3bdec 100644 --- a/tests/system/Database/Live/BadQueryTest.php +++ b/tests/system/Database/Live/BadQueryTest.php @@ -53,4 +53,22 @@ public function testBadQueryDebugFalse(): void $this->enableDBDebug(); } + + public function testPostgreBadQueryDebugTrueWithWarningsDisabled(): void + { + if ($this->db->DBDriver !== 'Postgre') { + $this->markTestSkipped('This test is only for Postgre.'); + } + + $this->enableDBDebug(); + $errorReporting = error_reporting(E_ALL & ~E_WARNING); + + try { + $this->expectException(DatabaseException::class); + $this->expectExceptionMessage('table_does_not_exist'); + $this->db->query('SELECT * FROM table_does_not_exist'); + } finally { + error_reporting($errorReporting); + } + } } diff --git a/tests/system/Validation/StrictRules/CreditCardRulesTest.php b/tests/system/Validation/StrictRules/CreditCardRulesTest.php index deda7d76f984..55a880839662 100644 --- a/tests/system/Validation/StrictRules/CreditCardRulesTest.php +++ b/tests/system/Validation/StrictRules/CreditCardRulesTest.php @@ -100,6 +100,16 @@ public static function provideValidCCNumber(): iterable 'abcd efgh ijkl mnop', false, ], + 'decimal_point_visa' => [ + 'visa', + '41.1111111111111', + false, + ], + 'decimal_point_mastercard' => [ + 'mastercard', + '5351367.37861108', + false, + ], 'bad_length' => [ 'amex', '3782 8224 6310 0051', diff --git a/user_guide_src/source/changelogs/v4.7.5.rst b/user_guide_src/source/changelogs/v4.7.5.rst index 5fc0cfce5578..deabaf4b7ab4 100644 --- a/user_guide_src/source/changelogs/v4.7.5.rst +++ b/user_guide_src/source/changelogs/v4.7.5.rst @@ -53,12 +53,14 @@ Bugs Fixed - **Cookie:** Fixed a bug where ``Cookie`` instances created with ``raw: true`` allowed invalid characters in cookie values rejected by ``setrawcookie()``. - **Cookie:** Fixed a bug where ``Cookie`` instances allowed invalid characters in path, domain, and prefix attributes rejected by ``setcookie()`` and ``setrawcookie()``. - **Database:** Fixed a bug where rebuilding a SQLite3 table (e.g., ``Forge::dropColumn()``, ``Forge::modifyColumn()``, ``Forge::dropForeignKey()`` and ``Forge::dropPrimaryKey()``) corrupted the table names referenced by its foreign keys when ``DBPrefix`` was set. +- **Database:** Fixed a bug where Postgre query failures were silently ignored when ``DBDebug`` was enabled and PHP warnings were disabled. A ``DatabaseException`` is now thrown. - **Debug:** Fixed a bug where ``Timer::start()`` treated ``0.0`` as an empty value and substituted the current time. - **Files:** Fixed a bug where ``File::move()`` and ``UploadedFile::move()`` set executable and overly permissive file permissions (``0777 & ~umask()`` instead of ``0666 & ~umask()``), and ``UploadedFile::move()`` targeted the parent directory instead of the destination file for ``chmod()``. - **Helpers:** Fixed a bug where ``get_dir_file_info()`` returned incomplete entries for subdirectories and missing files instead of omitting them. - **Honeypot:** Fixed a bug where bot detection returned an HTTP 500 response instead of 403 (Forbidden). - **I18n:** Fixed a bug where ``Time::today()``, ``Time::yesterday()``, and ``Time::tomorrow()`` ignored the specified ``$timezone`` and ``setTestNow()`` when calculating the day. - **Logger:** Fixed a bug where interpolating a log message with array or non-stringable context values could raise PHP warnings or errors. +- **Validation:** Fixed a bug where ``valid_cc_number`` accepted non-digit characters (e.g., a decimal point) in the card number. Such values could pass the Luhn check and triggered an ``Undefined array key`` warning inside it; the number is now checked with ``ctype_digit()``. See the repo's `CHANGELOG.md `_