Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Idn.php

function Idn::process

Parameters

string $domain:

array<string, bool> $options:

Return value

array<int, string>

See also

https://www.unicode.org/reports/tr46/#Processing

2 calls to Idn::process()
Idn::idn_to_ascii in vendor/symfony/polyfill-intl-idn/Idn.php
Idn::idn_to_utf8 in vendor/symfony/polyfill-intl-idn/Idn.php

File

vendor/symfony/polyfill-intl-idn/Idn.php, line 316

Class

Idn
@internal

Namespace

Symfony\Polyfill\Intl\Idn

Code

private static function process($domain, array $options, Info $info) {
    // If VerifyDnsLength is not set, we are doing ToUnicode otherwise we are doing ToASCII and
    // we need to respect the VerifyDnsLength option.
    $checkForEmptyLabels = !isset($options['VerifyDnsLength']) || $options['VerifyDnsLength'];
    if ($checkForEmptyLabels && '' === $domain) {
        $info->errors |= self::ERROR_EMPTY_LABEL;
        return [
            $domain,
        ];
    }
    // Step 1. Map each code point in the domain name string
    $domain = self::mapCodePoints($domain, $options, $info);
    // Step 2. Normalize the domain name string to Unicode Normalization Form C.
    if (!\Normalizer::isNormalized($domain, \Normalizer::FORM_C)) {
        $domain = \Normalizer::normalize($domain, \Normalizer::FORM_C);
    }
    // Step 3. Break the string into labels at U+002E (.) FULL STOP.
    $labels = explode('.', $domain);
    $lastLabelIndex = \count($labels) - 1;
    // Step 4. Convert and validate each label in the domain name string.
    foreach ($labels as $i => $label) {
        $validationOptions = $options;
        if ('xn--' === substr($label, 0, 4)) {
            // Step 4.1. If the label contains any non-ASCII code point (i.e., a code point greater than U+007F),
            // record that there was an error, and continue with the next label.
            if (preg_match('/[^\\x00-\\x7F]/', $label)) {
                $info->errors |= self::ERROR_PUNYCODE;
                continue;
            }
            // Step 4.2. Attempt to convert the rest of the label to Unicode according to Punycode [RFC3492]. If
            // that conversion fails, record that there was an error, and continue
            // with the next label. Otherwise replace the original label in the string by the results of the
            // conversion.
            try {
                $label = self::punycodeDecode(substr($label, 4));
            } catch (\Exception $e) {
                $info->errors |= self::ERROR_PUNYCODE;
                continue;
            }
            $validationOptions['Transitional_Processing'] = false;
            $labels[$i] = $label;
        }
        self::validateLabel($label, $info, $validationOptions, $i > 0 && $i === $lastLabelIndex);
    }
    if ($info->bidiDomain && !$info->validBidiDomain) {
        $info->errors |= self::ERROR_BIDI;
    }
    // Any input domain name string that does not record an error has been successfully
    // processed according to this specification. Conversely, if an input domain_name string
    // causes an error, then the processing of the input domain_name string fails. Determining
    // what to do with error input is up to the caller, and not in the scope of this document.
    return $labels;
}
RSS feed
Powered by Drupal