Change conditions for Domain validation

Domains can have `--` as long as they don't start or end with `-` in its
parts.
This commit is contained in:
Henrique Moody 2017-04-28 13:06:29 +02:00
parent 37a71de7d0
commit c931e2504b
No known key found for this signature in database
GPG key ID: 221E9281655813A6
2 changed files with 10 additions and 11 deletions

View file

@ -29,16 +29,12 @@ class Domain extends AbstractComposite
new Alnum('-'),
new Not(new StartsWith('-')),
new OneOf(
new Not(
new Contains('--')
),
new AllOf(
new StartsWith('xn--'),
new Callback(function ($str) {
return substr_count($str, '--') == 1;
})
)
)
new Not(new Contains('--')),
new Callback(function ($str) {
return substr_count($str, '--') == 1;
})
),
new Not(new EndsWith('-'))
);
}

View file

@ -67,6 +67,9 @@ class DomainTest extends \PHPUnit_Framework_TestCase
['xn--bcher-kva.ch'],
['mail.xn--bcher-kva.ch'],
['example-hyphen.com'],
['example--valid.com'],
['std--a.com'],
['r--w.com'],
];
}
@ -76,10 +79,10 @@ class DomainTest extends \PHPUnit_Framework_TestCase
[null],
[''],
['2222222domain.local'],
['example--invalid.com'],
['-example-invalid.com'],
['example.invalid.-com'],
['xn--bcher--kva.ch'],
['example.invalid-.com'],
['1.2.3.256'],
['1.2.3.4'],
];