File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -38,7 +38,10 @@ public function tld(?string $tld = null): string|self
3838
3939 $ this ->tld = $ tld ;
4040
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 ));
4245
4346 if (!validate_domain_root (trim ($ root , '. ' ))) {
4447 $ this ->isValid = false ;
Original file line number Diff line number Diff line change 6262 it ('is not empty domain ' , fn () => expect ($ host ->domain ())->toBe ('adro.com ' ));
6363 it ("is same as $ url " , fn () => expect ($ host ->original ())->toBe ($ url ));
6464});
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