File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -38,7 +38,10 @@ public function tld(?string $tld = null): string|self
38
38
39
39
$ this ->tld = $ tld ;
40
40
41
- $ root = str_replace (strval ($ this ->tld ), '' , strval ($ this ->host ));
41
+ $ escaped = str_replace ('. ' , '\. ' , '. ' . strval ($ this ->tld ));
42
+
43
+ /** @var string $root */
44
+ $ root = preg_replace ("/ $ escaped$/ " , '' , strval ($ this ->host ));
42
45
43
46
if (!validate_domain_root (trim ($ root , '. ' ))) {
44
47
$ this ->isValid = false ;
Original file line number Diff line number Diff line change 62
62
it ('is not empty domain ' , fn () => expect ($ host ->domain ())->toBe ('adro.com ' ));
63
63
it ("is same as $ url " , fn () => expect ($ host ->original ())->toBe ($ url ));
64
64
});
65
+
66
+ describe ('Root domain is correctly obtained when the tld substring is contained in it ' , function () {
67
+ $ validator = getInstance ();
68
+ $ url = 'a.b.c.compass.com ' ;
69
+ $ host = $ validator ->validate ($ url );
70
+
71
+ it ("$ url is valid domain " , fn () => expect ($ host ->isValid ())->toBeTrue ());
72
+ it ("from $ url - compass.com is the domain " , fn () => expect ($ host ->domain ())->toBe ('compass.com ' ));
73
+
74
+ $ validator = getInstance ();
75
+ $ url = 'compass.com ' ;
76
+ $ host = $ validator ->validate ($ url );
77
+
78
+ it ("$ url is valid domain " , fn () => expect ($ host ->isValid ())->toBeTrue ());
79
+ it ("from $ url - compass.com is the domain " , fn () => expect ($ host ->domain ())->toBe ('compass.com ' ));
80
+ });
You can’t perform that action at this time.
0 commit comments