Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix for #5894 - .il Domain checking #5900

Closed
wants to merge 2 commits into from

5 participants

@moderndeveloperllc

Fix for Issue #5894

  • .il validation for Hebrew and Latin domain names;
  • Update validTLDs from IANA website;
  • Add a few more Cyrillic IDN checking strings from IANA website;
  • Use UTF8 string wrapper for strlen calls;
  • Clean up TLD checking (if we are using getTldCheck() == true we don't need any further checking of the TLD validity);
  • Add new tests for some of the new UTF-8 TLDs

There is more cleaning up to do in this class:

  • TLDs like .asia can take Chinese, Japanese, and Korean characters. Current logic only allows one file to be imported at a time.
  • Should probably have a idn_to_utf8() short-circuit in decodePunycode() for those with the intl extension.
  • Need to check the other new TLDs like .tokyo to see if they use IDN strings too
@moderndeveloperllc moderndeveloperllc Update validTLDs from http://www.iana.org/domains/root/db/ 9fe9f29
@moderndeveloperllc moderndeveloperllc Fix for issue #5894 - .il validation for Hebrew and Latin domain name…
…s; update validTLDs from IANA website; Add a few more Cyrillic IDN checking strings from IANA website; Use UTF8 string wrapper for strlen calls; Clean up TLD checking (if we are using getTldCheck() == true we don't need any further checking of the TLD validity); Add new tests for some of the new UTF-8 TLDs
b59690f
@moderndeveloperllc

Not sure why Travis failed. The unit tests I updated passed and there were no formatting issues.

@Ocramius
Collaborator

@moderndeveloperllc the failure is not related with your issue

@weierophinney weierophinney added this to the 2.2.6 milestone
@weierophinney weierophinney closed this pull request from a commit
@weierophinney weierophinney Merge branch 'hotfix/5900'
Close #5900
Fixes #5894
4c617fd
@weierophinney weierophinney referenced this pull request from a commit
@weierophinney weierophinney Merge branch 'hotfix/5900' into develop
Forward port #5900
09d250a
@weierophinney weierophinney self-assigned this
@moderndeveloperllc moderndeveloperllc deleted the unknown repository branch
@dol

This commit is incomplete. No updated test cases are provided. I guess the commit breaks the validation of TLD's longer than 10 characters (e.g. .photography). See https://github.com/zendframework/zf2/blob/master/library/Zend/Validator/Hostname.php#L525

@dol Good catch. That regex isn't new logic, but I did miss it when I was updating the TLD checking logic. New tests were put in from non-latin TLDs, but not for one of the new, longer latin TLDs. I'll have to check and see if there are actually any restrictions on TLD length anymore. It'll make me check the list again too. In the new wild west of gTLDs, it grows on a daily basis.

I already issued a PR #5992 addressing this issue.

@weierophinney weierophinney referenced this pull request from a commit in zendframework/zend-validator
@weierophinney weierophinney Merge pull request zendframework/zf2#5900 from moderndeveloperllc/fea…
…ture/5894

Fix for zendframework/zf2#5894 - .il Domain checking
09f5f58
@weierophinney weierophinney referenced this pull request from a commit in zendframework/zend-validator
@weierophinney weierophinney Merge branch 'hotfix/5900' 835664d
@weierophinney weierophinney referenced this pull request from a commit in zendframework/zend-validator
@weierophinney weierophinney Merge branch 'hotfix/5900' into develop 526d261
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 3, 2014
  1. @moderndeveloperllc
  2. @moderndeveloperllc

    Fix for issue #5894 - .il validation for Hebrew and Latin domain name…

    moderndeveloperllc authored
    …s; update validTLDs from IANA website; Add a few more Cyrillic IDN checking strings from IANA website; Use UTF8 string wrapper for strlen calls; Clean up TLD checking (if we are using getTldCheck() == true we don't need any further checking of the TLD validity); Add new tests for some of the new UTF-8 TLDs
This page is out of date. Refresh to see the latest.
View
123 library/Zend/Validator/Hostname.php
@@ -74,25 +74,41 @@ class Hostname extends AbstractValidator
* @var array
*/
protected $validTlds = array(
- 'ac', 'ad', 'ae', 'aero', 'af', 'ag', 'ai', 'al', 'am', 'an', 'ao', 'aq', 'ar', 'arpa',
- 'as', 'asia', 'at', 'au', 'aw', 'ax', 'az', 'ba', 'bb', 'bd', 'be', 'bf', 'bg', 'bh', 'bi',
- 'biz', 'bj', 'bm', 'bn', 'bo', 'br', 'bs', 'bt', 'bv', 'bw', 'by', 'bz', 'ca', 'cat', 'cc',
- 'cd', 'cf', 'cg', 'ch', 'ci', 'ck', 'cl', 'cm', 'cn', 'co', 'com', 'coop', 'cr', 'cu',
- 'cv', 'cx', 'cy', 'cz', 'de', 'dj', 'dk', 'dm', 'do', 'dz', 'ec', 'edu', 'ee', 'eg', 'er',
- 'es', 'et', 'eu', 'fi', 'fj', 'fk', 'fm', 'fo', 'fr', 'ga', 'gb', 'gd', 'ge', 'gf', 'gg',
- 'gh', 'gi', 'gl', 'gm', 'gn', 'gov', 'gp', 'gq', 'gr', 'gs', 'gt', 'gu', 'gw', 'gy', 'hk',
- 'hm', 'hn', 'hr', 'ht', 'hu', 'id', 'ie', 'il', 'im', 'in', 'info', 'int', 'io', 'iq',
- 'ir', 'is', 'it', 'je', 'jm', 'jo', 'jobs', 'jp', 'ke', 'kg', 'kh', 'ki', 'km', 'kn', 'kp',
- 'kr', 'kw', 'ky', 'kz', 'la', 'lb', 'lc', 'li', 'lk', 'lr', 'ls', 'lt', 'lu', 'lv', 'ly',
- 'ma', 'mc', 'md', 'me', 'mg', 'mh', 'mil', 'mk', 'ml', 'mm', 'mn', 'mo', 'mobi', 'mp',
- 'mq', 'mr', 'ms', 'mt', 'mu', 'museum', 'mv', 'mw', 'mx', 'my', 'mz', 'na', 'name', 'nc',
- 'ne', 'net', 'nf', 'ng', 'ni', 'nl', 'no', 'np', 'nr', 'nu', 'nz', 'om', 'org', 'pa', 'pe',
- 'pf', 'pg', 'ph', 'pk', 'pl', 'pm', 'pn', 'pr', 'pro', 'ps', 'pt', 'pw', 'py', 'qa', 're',
- 'ro', 'rs', 'ru', 'rw', 'sa', 'sb', 'sc', 'sd', 'se', 'sg', 'sh', 'si', 'sj', 'sk', 'sl',
- 'sm', 'sn', 'so', 'sr', 'st', 'su', 'sv', 'sy', 'sz', 'tc', 'td', 'tel', 'tf', 'tg', 'th',
- 'tj', 'tk', 'tl', 'tm', 'tn', 'to', 'tp', 'tr', 'travel', 'tt', 'tv', 'tw', 'tz', 'ua',
- 'ug', 'uk', 'um', 'us', 'uy', 'uz', 'va', 'vc', 've', 'vg', 'vi', 'vn', 'vu', 'wf', 'ws',
- 'xxx', 'ye', 'yt', 'yu', 'za', 'zm', 'zw'
+ 'ac', 'academy', 'actor', 'ad', 'ae', 'aero', 'af', 'ag', 'agency', 'ai', 'al', 'am', 'an', 'ao', 'aq', 'ar',
+ 'arpa', 'as', 'asia', 'at', 'au', 'aw', 'ax', 'az', 'ba', 'bar', 'bargains', 'bb', 'bd', 'be', 'berlin', 'best',
+ 'bf', 'bg', 'bh', 'bi', 'bike', 'biz', 'bj', 'bl', 'blue', 'bm', 'bn', 'bo', 'boutique', 'bq', 'br', 'bs', 'bt',
+ 'build', 'builders', 'buzz', 'bv', 'bw', 'by', 'bz', 'ca', 'cab', 'camera', 'camp', 'cards', 'careers', 'cat',
+ 'catering', 'cc', 'cd', 'center', 'ceo', 'cf', 'cg', 'ch', 'cheap', 'christmas', 'ci', 'ck', 'cl', 'cleaning',
+ 'clothing', 'club', 'cm', 'cn', 'co', 'codes', 'coffee', 'com', 'community', 'company', 'computer',
+ 'construction', 'contractors', 'cool', 'coop', 'cr', 'cruises', 'cu', 'cv', 'cw', 'cx', 'cy', 'cz', 'dance',
+ 'dating', 'de', 'democrat', 'diamonds', 'directory', 'dj', 'dk', 'dm', 'do', 'domains', 'dz', 'ec', 'edu',
+ 'education', 'ee', 'eg', 'eh', 'email', 'enterprises', 'equipment', 'er', 'es', 'estate', 'et', 'eu', 'events',
+ 'expert', 'exposed', 'farm', 'fi', 'fish', 'fj', 'fk', 'flights', 'florist', 'fm', 'fo', 'foundation', 'fr',
+ 'futbol', 'ga', 'gallery', 'gb', 'gd', 'ge', 'gf', 'gg', 'gh', 'gi', 'gift', 'gl', 'glass', 'gm', 'gn', 'gov',
+ 'gp', 'gq', 'gr', 'graphics', 'gs', 'gt', 'gu', 'guitars', 'guru', 'gw', 'gy', 'hk', 'hm', 'hn', 'holdings',
+ 'holiday', 'house', 'hr', 'ht', 'hu', 'id', 'ie', 'il', 'im', 'immobilien', 'in', 'industries', 'info',
+ 'institute', 'int', 'international', 'io', 'iq', 'ir', 'is', 'it', 'je', 'jm', 'jo', 'jobs', 'jp', 'kaufen',
+ 'ke', 'kg', 'kh', 'ki', 'kim', 'kitchen', 'kiwi', 'km', 'kn', 'kp', 'kr', 'kred', 'kw', 'ky', 'kz', 'la',
+ 'land', 'lb', 'lc', 'li', 'lighting', 'limo', 'link', 'lk', 'lr', 'ls', 'lt', 'lu', 'luxury', 'lv', 'ly', 'ma',
+ 'management', 'mango', 'marketing', 'mc', 'md', 'me', 'menu', 'mf', 'mg', 'mh', 'mil', 'mk', 'ml', 'mm', 'mn',
+ 'mo', 'mobi', 'moda', 'monash', 'mp', 'mq', 'mr', 'ms', 'mt', 'mu', 'museum', 'mv', 'mw', 'mx', 'my', 'mz',
+ 'na', 'nagoya', 'name', 'nc', 'ne', 'net', 'neustar', 'nf', 'ng', 'ni', 'ninja', 'nl', 'no', 'np', 'nr', 'nu',
+ 'nz', 'om', 'onl', 'org', 'pa', 'partners', 'parts', 'pe', 'pf', 'pg', 'ph', 'photo', 'photography', 'photos',
+ 'pics', 'pink', 'pk', 'pl', 'plumbing', 'pm', 'pn', 'post', 'pr', 'pro', 'productions', 'properties', 'ps',
+ 'pt', 'pub', 'pw', 'py', 'qa', 'qpon', 're', 'recipes', 'red', 'rentals', 'repair', 'report', 'reviews', 'rich',
+ 'ro', 'rs', 'ru', 'ruhr', 'rw', 'sa', 'sb', 'sc', 'sd', 'se', 'sexy', 'sg', 'sh', 'shiksha', 'shoes', 'si',
+ 'singles', 'sj', 'sk', 'sl', 'sm', 'sn', 'so', 'social', 'solar', 'solutions', 'sr', 'ss', 'st', 'su',
+ 'supplies', 'supply', 'support', 'sv', 'sx', 'sy', 'systems', 'sz', 'tattoo', 'tc', 'td', 'technology', 'tel',
+ 'tf', 'tg', 'th', 'tienda', 'tips', 'tj', 'tk', 'tl', 'tm', 'tn', 'to', 'today', 'tokyo', 'tools', 'tp', 'tr',
+ 'training', 'travel', 'tt', 'tv', 'tw', 'tz', 'ua', 'ug', 'uk', 'um', 'uno', 'us', 'uy', 'uz', 'va',
+ 'vacations', 'vc', 've', 'ventures', 'vg', 'vi', 'viajes', 'villas', 'vision', 'vn', 'voting', 'voyage', 'vu',
+ 'wang', 'watch', 'wed', 'wf', 'wien', 'wiki', 'works', 'ws', '测试', 'परीक्षा', '集团', '在线', '한국', 'ভারত',
+ 'বাংলা', '公益', '公司', '移动', '我爱你', 'испытание', 'қаз', 'онлайн', 'сайт', 'срб', '테스트', '삼성',
+ 'சிங்கப்பூர்', 'дети', 'טעסט', '中文网', '中信', '中国', '中國', 'భారత్', 'ලංකා', '測試', 'ભારત', 'भारत',
+ 'آزمایشی', 'பரிட்சை', '网络', 'укр', '香港', 'δοκιμή', 'إختبار', '台湾', '台灣', 'мон',
+ 'الجزائر', 'عمان', 'ایران', 'امارات', 'بازار', 'پاکستان', 'الاردن', 'بھارت', 'المغرب', 'السعودية', 'سودان', 'مليسيا', 'شبكة', 'გე',
+ 'ไทย', 'سورية', 'рф', 'تونس', 'みんな', 'ਭਾਰਤ', '游戏', 'مصر', 'قطر', 'இலங்கை', 'இந்தியா', '新加坡', 'فلسطين',
+ 'テスト', '政务', 'xxx', 'xyz', 'ye', 'yt', 'za', 'zm', 'zone', 'zw'
);
/**
@@ -115,6 +131,7 @@ class Hostname extends AbstractValidator
* (.FI) Finland http://www.ficora.fi/en/index/palvelut/fiverkkotunnukset/aakkostenkaytto.html
* (.GR) Greece https://grweb.ics.forth.gr/CharacterTable1_en.jsp
* (.HU) Hungary http://www.domain.hu/domain/English/szabalyzat/szabalyzat.html
+ * (.IL) Israel http://www.isoc.org.il/domains/il-domain-rules.html
* (.INFO) International http://www.nic.info/info/idn
* (.IO) British Indian Ocean Territory http://www.nic.io/IO-IDN-Policy.pdf
* (.IR) Iran http://www.nic.ir/Allowable_Characters_dot-iran
@@ -172,6 +189,8 @@ class Hostname extends AbstractValidator
'GR' => array(1 => '/^[\x{002d}0-9a-zΆΈΉΊΌΎ-ΡΣ-ώἀ-ἕἘ-Ἕἠ-ὅὈ-Ὅὐ-ὗὙὛὝὟ-ώᾀ-ᾴᾶ-ᾼῂῃῄῆ-ῌῐ-ΐῖ-Ίῠ-Ῥῲῳῴῶ-ῼ]{1,63}$/iu'),
'HK' => 'Hostname/Cn.php',
'HU' => array(1 => '/^[\x{002d}0-9a-záéíóöúüőű]{1,63}$/iu'),
+ 'IL' => array(1 => '/^[\x{002d}0-9\x{05D0}-\x{05EA}]{1,63}$/iu',
+ 2 => '/^[\x{002d}0-9a-z]{1,63}$/i'),
'INFO'=> array(1 => '/^[\x{002d}0-9a-zäåæéöøü]{1,63}$/iu',
2 => '/^[\x{002d}0-9a-záéíóöúüőű]{1,63}$/iu',
3 => '/^[\x{002d}0-9a-záæéíðóöúýþ]{1,63}$/iu',
@@ -251,6 +270,10 @@ class Hostname extends AbstractValidator
'UA' => array(1 => '/^[\x{002d}0-9a-zабвгдежзийклмнопрстуфхцчшщъыьэюяѐёђѓєѕіїјљњћќѝўџґӂʼ]{1,63}$/iu'),
'VE' => array(1 => '/^[\x{002d}0-9a-záéíóúüñ]{1,63}$/iu'),
'VN' => array(1 => '/^[ÀÁÂÃÈÉÊÌÍÒÓÔÕÙÚÝàáâãèéêìíòóôõùúýĂăĐđĨĩŨũƠơƯư\x{1EA0}-\x{1EF9}]{1,63}$/iu'),
+ 'мон' => array(1 => '/^[\x{002d}0-9\x{0430}-\x{044F}]{1,63}$/iu'),
+ 'срб' => array(1 => '/^[\x{002d}0-9а-ик-шђјљњћџ]{1,63}$/iu'),
+ 'сайт' => array(1 => '/^[\x{002d}0-9а-яёіїѝйўґг]{1,63}$/iu'),
+ 'онлайн' => array(1 => '/^[\x{002d}0-9а-яёіїѝйўґг]{1,63}$/iu'),
'中国' => 'Hostname/Cn.php',
'中國' => 'Hostname/Cn.php',
'ලංකා' => array(1 => '/^[\x{0d80}-\x{0dff}]{1,63}$/iu'),
@@ -266,6 +289,7 @@ class Hostname extends AbstractValidator
'مصر' => array(1 => '/^[\x{0621}-\x{0624}\x{0626}-\x{063A}\x{0641}\x{0642}\x{0644}-\x{0648}\x{067E}\x{0686}\x{0698}\x{06A9}\x{06AF}\x{06CC}\x{06F0}-\x{06F9}]{1,30}$/iu'),
'இலங்கை' => array(1 => '/^[\x{0b80}-\x{0bff}]{1,63}$/iu'),
'فلسطين' => array(1 => '/^[\x{0621}-\x{0624}\x{0626}-\x{063A}\x{0641}\x{0642}\x{0644}-\x{0648}\x{067E}\x{0686}\x{0698}\x{06A9}\x{06AF}\x{06CC}\x{06F0}-\x{06F9}]{1,30}$/iu'),
+ 'شبكة' => array(1 => '/^[\x{0621}-\x{0624}\x{0626}-\x{063A}\x{0641}\x{0642}\x{0644}-\x{0648}\x{067E}\x{0686}\x{0698}\x{06A9}\x{06AF}\x{06CC}\x{06F0}-\x{06F9}]{1,30}$/iu'),
);
protected $idnLength = array(
@@ -284,6 +308,7 @@ class Hostname extends AbstractValidator
'تونس' => array(1 => 30),
'مصر' => array(1 => 30),
'فلسطين' => array(1 => 30),
+ 'شبكة' => array(1 => 30),
'中国' => array(1 => 20),
'中國' => array(1 => 20),
'香港' => array(1 => 20),
@@ -352,6 +377,7 @@ public function getIpValidator()
}
/**
+ *
* @param Ip $ipValidator OPTIONAL
* @return Hostname;
*/
@@ -452,8 +478,9 @@ public function isValid($value)
$this->setValue($value);
// Check input against IP address schema
- if (preg_match('/^[0-9a-f:.]*$/i', $value) &&
- $this->getIpValidator()->setTranslator($this->getTranslator())->isValid($value)) {
+ if (preg_match('/^[0-9a-f:.]*$/i', $value) && $this->getIpValidator()
+ ->setTranslator($this->getTranslator())
+ ->isValid($value)) {
if (!($this->getAllow() & self::ALLOW_IP)) {
$this->error(self::IP_ADDRESS_NOT_ALLOWED);
return false;
@@ -477,21 +504,26 @@ public function isValid($value)
$domainParts = explode('.', $value);
// Prevent partial IP V4 addresses (ending '.')
- if ((count($domainParts) == 4) && preg_match('/^[0-9.a-e:.]*$/i', $value) &&
- $this->getIpValidator()->setTranslator($this->getTranslator())->isValid($value)) {
+ if ((count($domainParts) == 4) && preg_match('/^[0-9.a-e:.]*$/i', $value) && $this->getIpValidator()
+ ->setTranslator($this->getTranslator())
+ ->isValid($value)) {
$this->error(self::INVALID_LOCAL_NAME);
}
+ $utf8StrWrapper = StringUtils::getWrapper('UTF-8');
+
// Check input against DNS hostname schema
- if ((count($domainParts) > 1) && (strlen($value) >= 4) && (strlen($value) <= 254)) {
- $utf8StrWrapper = StringUtils::getWrapper('UTF-8');
- $status = false;
+ if ((count($domainParts) > 1)
+ && ($utf8StrWrapper->strlen($value) >= 4)
+ && ($utf8StrWrapper->strlen($value) <= 254))
+ {
+ $status = false;
do {
// First check TLD
$matches = array();
- if (preg_match('/([^.]{2,10})$/i', end($domainParts), $matches) ||
- (array_key_exists(end($domainParts), $this->validIdns))) {
+ if (preg_match('/([^.]{2,10})$/iu', end($domainParts), $matches)
+ || (array_key_exists(end($domainParts), $this->validIdns))) {
reset($domainParts);
// Hostname characters are: *(label dot)(label dot label); max 254 chars
@@ -500,26 +532,31 @@ public function isValid($value)
// ldh: alpha / digit / dash
// Match TLD against known list
- $this->tld = strtolower($matches[1]);
+ $this->tld = strtoupper($matches[1]);
if ($this->getTldCheck()) {
- if (!in_array($this->tld, $this->validTlds)) {
+ if (!in_array(strtolower($this->tld), $this->validTlds)
+ && !in_array($this->tld, $this->validTlds)) {
$this->error(self::UNKNOWN_TLD);
$status = false;
break;
}
+ // We have already validated that the TLD is fine. We don't want it to go through the below
+ // checks as new UTF-8 TLDs will incorrectly fail if there is no IDN regex for it.
+ array_pop($domainParts);
}
/**
* Match against IDN hostnames
* Note: Keep label regex short to avoid issues with long patterns when matching IDN hostnames
+ *
* @see Hostname\Interface
*/
$regexChars = array(0 => '/^[a-z0-9\x2d]{1,63}$/i');
- if ($this->getIdnCheck() && isset($this->validIdns[strtoupper($this->tld)])) {
- if (is_string($this->validIdns[strtoupper($this->tld)])) {
- $regexChars += include __DIR__ .'/'. $this->validIdns[strtoupper($this->tld)];
+ if ($this->getIdnCheck() && isset($this->validIdns[$this->tld])) {
+ if (is_string($this->validIdns[$this->tld])) {
+ $regexChars += include __DIR__ . '/' . $this->validIdns[$this->tld];
} else {
- $regexChars += $this->validIdns[strtoupper($this->tld)];
+ $regexChars += $this->validIdns[$this->tld];
}
}
@@ -535,9 +572,9 @@ public function isValid($value)
}
// Check dash (-) does not start, end or appear in 3rd and 4th positions
- if ((strpos($domainPart, '-') === 0)
- || ((strlen($domainPart) > 2) && (strpos($domainPart, '-', 2) == 2) && (strpos($domainPart, '-', 3) == 3))
- || (strpos($domainPart, '-') === (strlen($domainPart) - 1))) {
+ if (($utf8StrWrapper->strpos($domainPart, '-') === 0)
+ || (($utf8StrWrapper->strlen($domainPart) > 2) && ($utf8StrWrapper->strpos($domainPart, '-', 2) == 2) && ($utf8StrWrapper->strpos($domainPart, '-', 3) == 3))
+ || ($utf8StrWrapper->strpos($domainPart, '-') === ($utf8StrWrapper->strlen($domainPart) - 1))) {
$this->error(self::INVALID_DASH);
$status = false;
break 2;
@@ -551,13 +588,14 @@ public function isValid($value)
ErrorHandler::stop();
if ($status > 0) {
$length = 63;
- if (array_key_exists(strtoupper($this->tld), $this->idnLength)
- && (array_key_exists($regexKey, $this->idnLength[strtoupper($this->tld)]))) {
- $length = $this->idnLength[strtoupper($this->tld)];
+ if (array_key_exists($this->tld, $this->idnLength)
+ && (array_key_exists($regexKey, $this->idnLength[$this->tld]))) {
+ $length = $this->idnLength[$this->tld];
}
if ($utf8StrWrapper->strlen($domainPart) > $length) {
$this->error(self::INVALID_HOSTNAME);
+ $status = false;
} else {
$checked = true;
break;
@@ -589,6 +627,7 @@ public function isValid($value)
}
} elseif ($this->getAllow() & self::ALLOW_DNS) {
$this->error(self::INVALID_HOSTNAME);
+ $status = false;
}
// Check for URI Syntax (RFC3986)
@@ -628,10 +667,10 @@ public function isValid($value)
/**
* Decodes a punycode encoded string to it's original utf8 string
- * In case of a decoding failure the original string is returned
+ * Returns false in case of a decoding failure.
*
* @param string $encoded Punycode encoded string to decode
- * @return string
+ * @return string|false
*/
protected function decodePunycode($encoded)
{
View
49 tests/ZendTest/Validator/HostnameTest.php
@@ -449,6 +449,49 @@ public function testIDNSI()
$this->assertFalse($validator->isValid('رات.si'));
}
+ /**
+ * @group Issue #5894 - Add .il IDN domain checking; add new TLDs
+ */
+ public function testIDNIL()
+ {
+ $validator = new Hostname(Hostname::ALLOW_ALL);
+
+ // Check .IL TLD matching
+ $valuesExpected = array(
+ array(true, array('xn----zhcbgfhe2aacg8fb5i.org.il', 'מבחן.il', 'מבחן123.il')),
+ array(false, array('tבדיקה123.il', 'رات.il')) // Can't mix Latin and Hebrew character sets (except digits)
+ );
+ foreach ($valuesExpected as $element) {
+ foreach ($element[1] as $input) {
+ $this->assertEquals(
+ $element[0],
+ $validator->isValid($input),
+ implode("\n", $validator->getMessages()) .' - '. $input
+ );
+ }
+ }
+ }
+
+ public function testAdditionalUTF8TLDs()
+ {
+ $validator = new Hostname(Hostname::ALLOW_ALL);
+
+ // Check UTF-8 TLD matching
+ $valuesExpected = array(
+ array(true, array('test123.δοκιμή', 'тест.рф', 'туршилтын.мон')),
+ array(false, array('சோதனை3.இலங்கை', 'رات.мон'))
+ );
+ foreach ($valuesExpected as $element) {
+ foreach ($element[1] as $input) {
+ $this->assertEquals(
+ $element[0],
+ $validator->isValid($input),
+ implode("\n", $validator->getMessages()) .' - '. $input
+ );
+ }
+ }
+ }
+
public function testIDNIT()
{
$validator = new Hostname(Hostname::ALLOW_ALL);
@@ -462,14 +505,12 @@ public function testIDNIT()
public function testEqualsMessageTemplates()
{
$validator = $this->validator;
- $this->assertAttributeEquals($validator->getOption('messageTemplates'),
- 'messageTemplates', $validator);
+ $this->assertAttributeEquals($validator->getOption('messageTemplates'), 'messageTemplates', $validator);
}
public function testEqualsMessageVariables()
{
$validator = $this->validator;
- $this->assertAttributeEquals($validator->getOption('messageVariables'),
- 'messageVariables', $validator);
+ $this->assertAttributeEquals($validator->getOption('messageVariables'), 'messageVariables', $validator);
}
}
Something went wrong with that request. Please try again.