Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bfc8b1e

Browse files
committed
bug #44119 [HttpClient][Mime] Add correct IDN flags for IDNA2008 compliance (j-bernard)
This PR was squashed before being merged into the 4.4 branch. Discussion ---------- [HttpClient][Mime] Add correct IDN flags for IDNA2008 compliance | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | #44091 #44092 | License | MIT Fix #44091 Fix #44092 Commits ------- 22d642e [HttpClient][Mime] Add correct IDN flags for IDNA2008 compliance
2 parents 38f3c12 + 22d642e commit bfc8b1e

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

src/Symfony/Component/HttpClient/HttpClientTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ private static function parseUrl(string $url, array $query = [], array $allowedS
456456
throw new InvalidArgumentException(sprintf('Unsupported IDN "%s", try enabling the "intl" PHP extension or running "composer require symfony/polyfill-intl-idn".', $host));
457457
}
458458

459-
$host = \defined('INTL_IDNA_VARIANT_UTS46') ? idn_to_ascii($host, \IDNA_DEFAULT, \INTL_IDNA_VARIANT_UTS46) ?: strtolower($host) : strtolower($host);
459+
$host = \defined('INTL_IDNA_VARIANT_UTS46') ? idn_to_ascii($host, \IDNA_DEFAULT | \IDNA_USE_STD3_RULES | \IDNA_CHECK_BIDI | \IDNA_CHECK_CONTEXTJ | \IDNA_NONTRANSITIONAL_TO_ASCII, \INTL_IDNA_VARIANT_UTS46) ?: strtolower($host) : strtolower($host);
460460
$host .= $port ? ':'.$port : '';
461461
}
462462

src/Symfony/Component/HttpClient/Tests/HttpClientTraitTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ public function provideParseUrl(): iterable
160160
yield [[null, null, 'bar', '?a%5Bb%5Bc%5D=d', null], 'bar?a[b[c]=d', []];
161161
yield [[null, null, 'bar', '?a%5Bb%5D%5Bc%5D=dd', null], 'bar?a[b][c]=d&e[f]=g', ['a' => ['b' => ['c' => 'dd']], 'e[f]' => null]];
162162
yield [[null, null, 'bar', '?a=b&a%5Bb%20c%5D=d&e%3Df=%E2%9C%93', null], 'bar?a=b', ['a' => ['b c' => 'd'], 'e=f' => '']];
163+
// IDNA 2008 compliance
164+
yield [['https:', '//xn--fuball-cta.test', null, null, null], 'https://fußball.test'];
163165
}
164166

165167
/**

src/Symfony/Component/Mime/Encoder/IdnAddressEncoder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function encodeString(string $address): string
4343
}
4444

4545
if (preg_match('/[^\x00-\x7F]/', $domain)) {
46-
$address = sprintf('%s@%s', $local, idn_to_ascii($domain, 0, \INTL_IDNA_VARIANT_UTS46));
46+
$address = sprintf('%s@%s', $local, idn_to_ascii($domain, \IDNA_DEFAULT | \IDNA_USE_STD3_RULES | \IDNA_CHECK_BIDI | \IDNA_CHECK_CONTEXTJ | \IDNA_NONTRANSITIONAL_TO_ASCII, \INTL_IDNA_VARIANT_UTS46));
4747
}
4848
}
4949

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Symfony\Component\Mime\Encoder;
4+
5+
use PHPUnit\Framework\TestCase;
6+
7+
class IdnAddressEncoderTest extends TestCase
8+
{
9+
public function testEncodeString()
10+
{
11+
$this->assertSame('[email protected]', (new IdnAddressEncoder())->encodeString('test@fußball.test'));
12+
}
13+
}

0 commit comments

Comments
 (0)