function Idn::validateLabel
Parameters
string $label:
array<string, bool> $options:
bool $canBeEmpty:
See also
https://www.unicode.org/reports/tr46/#Validity_Criteria
1 call to Idn::validateLabel()
- Idn::process in vendor/
symfony/ polyfill-intl-idn/ Idn.php
File
-
vendor/
symfony/ polyfill-intl-idn/ Idn.php, line 494
Class
- Idn
- @internal
Namespace
Symfony\Polyfill\Intl\IdnCode
private static function validateLabel($label, Info $info, array $options, $canBeEmpty) {
if ('' === $label) {
if (!$canBeEmpty && (!isset($options['VerifyDnsLength']) || $options['VerifyDnsLength'])) {
$info->errors |= self::ERROR_EMPTY_LABEL;
}
return;
}
// Step 1. The label must be in Unicode Normalization Form C.
if (!\Normalizer::isNormalized($label, \Normalizer::FORM_C)) {
$info->errors |= self::ERROR_INVALID_ACE_LABEL;
}
$codePoints = self::utf8Decode($label);
if ($options['CheckHyphens']) {
// Step 2. If CheckHyphens, the label must not contain a U+002D HYPHEN-MINUS character
// in both the thrid and fourth positions.
if (isset($codePoints[2], $codePoints[3]) && 0x2d === $codePoints[2] && 0x2d === $codePoints[3]) {
$info->errors |= self::ERROR_HYPHEN_3_4;
}
// Step 3. If CheckHyphens, the label must neither begin nor end with a U+002D
// HYPHEN-MINUS character.
if ('-' === substr($label, 0, 1)) {
$info->errors |= self::ERROR_LEADING_HYPHEN;
}
if ('-' === substr($label, -1, 1)) {
$info->errors |= self::ERROR_TRAILING_HYPHEN;
}
}
elseif ('xn--' === substr($label, 0, 4)) {
$info->errors |= self::ERROR_PUNYCODE;
}
// Step 4. The label must not contain a U+002E (.) FULL STOP.
if (false !== strpos($label, '.')) {
$info->errors |= self::ERROR_LABEL_HAS_DOT;
}
// Step 5. The label must not begin with a combining mark, that is: General_Category=Mark.
if (1 === preg_match(Regex::COMBINING_MARK, $label)) {
$info->errors |= self::ERROR_LEADING_COMBINING_MARK;
}
// Step 6. Each code point in the label must only have certain status values according to
// Section 5, IDNA Mapping Table:
$transitional = $options['Transitional_Processing'];
$useSTD3ASCIIRules = $options['UseSTD3ASCIIRules'];
foreach ($codePoints as $codePoint) {
$data = self::lookupCodePointStatus($codePoint, $useSTD3ASCIIRules);
$status = $data['status'];
if ('valid' === $status || !$transitional && 'deviation' === $status) {
continue;
}
$info->errors |= self::ERROR_DISALLOWED;
break;
}
// Step 7. If CheckJoiners, the label must satisify the ContextJ rules from Appendix A, in
// The Unicode Code Points and Internationalized Domain Names for Applications (IDNA)
// [IDNA2008].
if ($options['CheckJoiners'] && !self::isValidContextJ($codePoints, $label)) {
$info->errors |= self::ERROR_CONTEXTJ;
}
// Step 8. If CheckBidi, and if the domain name is a Bidi domain name, then the label must
// satisfy all six of the numbered conditions in [IDNA2008] RFC 5893, Section 2.
if ($options['CheckBidi'] && (!$info->bidiDomain || $info->validBidiDomain)) {
self::validateBidiLabel($label, $info);
}
}