Skip to content

Commit

Permalink
Change conditions for Domain validation
Browse files Browse the repository at this point in the history
Domains can have `--` as long as they don't start or end with `-` in its
parts.
  • Loading branch information
henriquemoody committed Jan 2, 2018
1 parent 37a71de commit c931e25
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
16 changes: 6 additions & 10 deletions library/Rules/Domain.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,12 @@ public function __construct($tldCheck = true)
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('-'))
);
}

Expand Down
5 changes: 4 additions & 1 deletion tests/unit/Rules/DomainTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ public function providerForDomain()
['xn--bcher-kva.ch'],
['mail.xn--bcher-kva.ch'],
['example-hyphen.com'],
['example--valid.com'],
['std--a.com'],
['r--w.com'],
];
}

Expand All @@ -76,10 +79,10 @@ public function providerForNotDomain()
[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'],
];
Expand Down

0 comments on commit c931e25

Please sign in to comment.