File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -229,7 +229,7 @@ public function endsWith(string $endsWith): static
229229 public function hostname (): static
230230 {
231231 return $ this ->postParse (static function (string $ string ) {
232- if (filter_var ($ string , FILTER_VALIDATE_DOMAIN )) {
232+ if (filter_var ($ string , FILTER_VALIDATE_DOMAIN , FILTER_FLAG_HOSTNAME )) {
233233 return $ string ;
234234 }
235235
Original file line number Diff line number Diff line change @@ -466,6 +466,32 @@ public function testParseWithInvalidHostname(): void
466466 }
467467 }
468468
469+ public function testParseWithInvalidHostnameWithInvalidLabelCharacters (): void
470+ {
471+ $ input = 'exa_mple.com ' ;
472+
473+ $ schema = (new StringSchema ())->hostname ();
474+
475+ try {
476+ $ schema ->parse ($ input );
477+
478+ throw new \Exception ('code should not be reached ' );
479+ } catch (ErrorsException $ errorsException ) {
480+ self ::assertSame ([
481+ [
482+ 'path ' => '' ,
483+ 'error ' => [
484+ 'code ' => 'string.hostname ' ,
485+ 'template ' => 'Invalid hostname {{given}} ' ,
486+ 'variables ' => [
487+ 'given ' => $ input ,
488+ ],
489+ ],
490+ ],
491+ ], $ errorsException ->errors ->jsonSerialize ());
492+ }
493+ }
494+
469495 public function testParseWithValidDomain (): void
470496 {
471497 $ input = 'example.com ' ;
You can’t perform that action at this time.
0 commit comments