From 7418a325f2485f8b2d7d9773d1da618636b6606c Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Fri, 29 Nov 2024 18:00:45 +0900 Subject: [PATCH 1/3] Fix type declarations and formatting in AbstractStrlen.php Ensure functions have correct type returns and optional parameters with default values. --- src/Rule/AbstractStrlen.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Rule/AbstractStrlen.php b/src/Rule/AbstractStrlen.php index 0ebb176..bde2121 100644 --- a/src/Rule/AbstractStrlen.php +++ b/src/Rule/AbstractStrlen.php @@ -72,7 +72,7 @@ protected function strlen(string $str): int return strlen(utf8_to_iso8859_1($str)); } - /** + /** * * Wrapper for `iconv_substr()` to throw an exception on malformed UTF-8. * @@ -87,10 +87,10 @@ protected function strlen(string $str): int * @throws Exception\MalformedUtf8 * */ - protected function substrIconv(string $str,int $start,int $length) + protected function substrIconv(string $str, int $start, ?int $length = null): string { $level = error_reporting(0); - $substr = iconv_substr($str,$start,$length, 'UTF-8'); + $substr = iconv_substr($str, $start, $length ?? 0, 'UTF-8'); error_reporting($level); if ($substr !== false) { @@ -111,7 +111,7 @@ protected function substrIconv(string $str,int $start,int $length) * @throws Exception\MalformedUtf8 * */ - protected function strlenIconv(string $str) + protected function strlenIconv(string $str): int { $level = error_reporting(0); $strlen = iconv_strlen($str, 'UTF-8'); From 58b051cd6d0eafa88edf5a14119ab9358c29ea6b Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Fri, 29 Nov 2024 18:38:42 +0900 Subject: [PATCH 2/3] Enhance email validation to handle missing domain parts This update improves the IDN to ASCII conversion by handling cases where the email address lacks a domain part or '@' symbol. By checking for these conditions, the function now gracefully returns the input as is, avoiding unnecessary warnings or errors during the conversion process. --- src/Rule/Validate/Email.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Rule/Validate/Email.php b/src/Rule/Validate/Email.php index 4ff6fdf..b4ea0c7 100644 --- a/src/Rule/Validate/Email.php +++ b/src/Rule/Validate/Email.php @@ -404,15 +404,24 @@ protected function intl(): bool */ protected function idnToAscii(string $email): string { + if (strpos($email, '@') === false) { + return $email; + } + $parts = explode('@', $email); - $domain = array_pop($parts); - if (! $parts) { - // no parts remaining, so no @ symbol, so not valid to begin with + + if (!isset($parts[1]) || empty($parts[1])) { return $email; } - // put the parts back together, with the domain part converted to ascii - return implode('@', $parts) . '@' . idn_to_ascii($domain, IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46); + $domain = array_pop($parts); + $localPart = implode('@', $parts); + + $asciiDomain = idn_to_ascii($domain, IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46); + if ($asciiDomain === false) { + return $email; + } + return $localPart . '@' . $asciiDomain; } /** From f1d18ea791758ce0fddf8e74036ccd0a36dfffb0 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Fri, 29 Nov 2024 18:39:07 +0900 Subject: [PATCH 3/3] Add PHP 8.3 and 8.4 to CI test matrix Updated the continuous integration workflow to include PHP versions 8.3 and 8.4 in the testing matrix. --- .github/workflows/continuous-integration.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index ef448ae..4e454ca 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -21,6 +21,8 @@ jobs: - '8.0' - '8.1' - '8.2' + - '8.3' + - '8.4' steps: - name: Checkout uses: actions/checkout@v1