Skip to content

Commit c931e25

Browse files
committed
Change conditions for Domain validation
Domains can have `--` as long as they don't start or end with `-` in its parts.
1 parent 37a71de commit c931e25

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

library/Rules/Domain.php

+6-10
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,12 @@ public function __construct($tldCheck = true)
2929
new Alnum('-'),
3030
new Not(new StartsWith('-')),
3131
new OneOf(
32-
new Not(
33-
new Contains('--')
34-
),
35-
new AllOf(
36-
new StartsWith('xn--'),
37-
new Callback(function ($str) {
38-
return substr_count($str, '--') == 1;
39-
})
40-
)
41-
)
32+
new Not(new Contains('--')),
33+
new Callback(function ($str) {
34+
return substr_count($str, '--') == 1;
35+
})
36+
),
37+
new Not(new EndsWith('-'))
4238
);
4339
}
4440

tests/unit/Rules/DomainTest.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ public function providerForDomain()
6767
['xn--bcher-kva.ch'],
6868
['mail.xn--bcher-kva.ch'],
6969
['example-hyphen.com'],
70+
['example--valid.com'],
71+
['std--a.com'],
72+
['r--w.com'],
7073
];
7174
}
7275

@@ -76,10 +79,10 @@ public function providerForNotDomain()
7679
[null],
7780
[''],
7881
['2222222domain.local'],
79-
['example--invalid.com'],
8082
['-example-invalid.com'],
8183
['example.invalid.-com'],
8284
['xn--bcher--kva.ch'],
85+
['example.invalid-.com'],
8386
['1.2.3.256'],
8487
['1.2.3.4'],
8588
];

0 commit comments

Comments
 (0)