Skip to content

Commit

Permalink
Merge pull request laminas#225 from mimmi20/fix-uninitialized-warning
Browse files Browse the repository at this point in the history
prevent warnings when using Puny encoded Hostnames
  • Loading branch information
Ocramius authored Jan 17, 2024
2 parents 0d28d32 + 931f411 commit 5c3fc8c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Hostname.php
Original file line number Diff line number Diff line change
Expand Up @@ -2212,6 +2212,10 @@ protected function decodePunycode($encoded)

for ($indexe = $separator ? $separator + 1 : 0; $indexe < $lengthe; ++$lengthd) {
for ($oldIndex = $index, $pos = 1, $key = 36; 1; $key += 36) {
if (! isset($encoded[$indexe])) {
break 2;
}

$hex = ord($encoded[$indexe++]);
$digit = $hex - 48 < 10 ? $hex - 22
: ($hex - 65 < 26 ? $hex - 65
Expand Down
10 changes: 10 additions & 0 deletions test/HostnameTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -685,4 +685,14 @@ public function testHostnameWithEmptyDomainPart(): void
{
self::assertFalse($this->validator->isValid('.com'));
}

public function testInvalidHostnameWithPunyEncodedDomainPart(): void
{
self::assertFalse($this->validator->isValid('xn--k.dk'));
}

public function testValidHostnameWithPunyEncodedDomainPart(): void
{
self::assertTrue($this->validator->isValid('xn--gld-sna.de'));
}
}

0 comments on commit 5c3fc8c

Please sign in to comment.