Skip to content

Commit

Permalink
Merge pull request #2564 from j-bernard/fix_2563
Browse files Browse the repository at this point in the history
Fix #2563: Provide the right flags to IDN methods for email addresses conversion
  • Loading branch information
Synchro committed Nov 19, 2021
2 parents e84b657 + 3c81f48 commit eaac722
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/PHPMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -1451,7 +1451,11 @@ public function punyencodeAddress($address)
$errorcode = 0;
if (defined('INTL_IDNA_VARIANT_UTS46')) {
//Use the current punycode standard (appeared in PHP 7.2)
$punycode = idn_to_ascii($domain, $errorcode, \INTL_IDNA_VARIANT_UTS46);
$punycode = idn_to_ascii(
$domain,
\IDNA_DEFAULT | \IDNA_USE_STD3_RULES | \IDNA_CHECK_BIDI | \IDNA_CHECK_CONTEXTJ | \IDNA_NONTRANSITIONAL_TO_ASCII,
\INTL_IDNA_VARIANT_UTS46
);
} elseif (defined('INTL_IDNA_VARIANT_2003')) {
//Fall back to this old, deprecated/removed encoding
$punycode = idn_to_ascii($domain, $errorcode, \INTL_IDNA_VARIANT_2003);
Expand Down
5 changes: 5 additions & 0 deletions test/PHPMailer/PunyencodeAddressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ public function dataPunyencodeAddressConversion()
'charset' => PHPMailer::CHARSET_UTF8,
'expected' => 'françois@xn--franois-xxa.ch',
],
'IDN conversion flags' => [
'input' => 'test@fußball.test',
'charset' => PHPMailer::CHARSET_UTF8,
'expected' => 'test@xn--fuball-cta.test',
],
];
}

Expand Down

0 comments on commit eaac722

Please sign in to comment.