symfony / polyfill

PHP polyfills

Home Page:https://symfony.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Discrepancy between the logic of idn_to_ascii and the polyfilled implementation

morozov opened this issue · comments

The native (PHP 7.4.5, ICU 66.1) idn_to_ascii implementation is unable to process a string that contains a leading or a trailing dash while the polyfilled implementation is able:

$part = 'xyz-';
var_dump(
    idn_to_ascii($part, IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46)
);
// bool(false)

var_dump(
    Symfony\Polyfill\Intl\Idn\Idn::idn_to_ascii($part, IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46)
);
// string(4) "xyz-"

The native implementation seems to be the correct one according to RFC 3492:

[…] IDNA using Punycode conforms to the RFC 952 rule that host name labels neither begin nor end with a hyphen-minus […].