ZF-12035: Zend_Validate_Hostname fails for punycode of IDN that not contain unicode characters

Description

Zend_Validate_Hostname always return {{CANNOT_DECODE_PUNYCODE}} for punycode of IDN that not contain unicode characters.

In protected function {{decodePunycode}} uses next code for validating punycode:


protected function decodePunycode($encoded)
{

// ...

$separator = strrpos($encoded, '-');
if ($separator > 0) {
    for ($x = 0; $x < $separator; ++$x) {
        // prepare decoding matrix
        $decoded[] = ord($encoded[$x]);
    }
} else {
    $this->_error(self::CANNOT_DECODE_PUNYCODE);
    return false;
}

// ...
}

As we know from procedure for Punycode encoding ASCII hyphen can be added to the encoded name after basic characters or if it is one of the basic characters. However hyphen may not be present in the Punycode(excluding xn--). For example, if the original name did not contain the basic characters:

{{пример.com (ACE: xn--e1afmkfd.com)}}

Thus function contains a bug that prevents the normal validation for multiple hostnames.

The proposed solution:

Fix incorrect part of function {{decodePunycode}}


protected function decodePunycode($encoded)
{

// ...

$decoded = array();
$separator = strrpos($encoded, '-');
if ($separator > 0) {
    for ($x = 0; $x < $separator; ++$x) {
        // prepare decoding matrix
        $decoded[] = ord($encoded[$x]);
    }
} else {
    $separator = 0;
}

// ...
}

Comments

No comments to display