Skip to content

Commit

Permalink
Allow underscores in hostnames (librenms#16683)
Browse files Browse the repository at this point in the history
  • Loading branch information
laf authored Nov 11, 2024
1 parent e3cc987 commit 66efd42
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion LibreNMS/Util/Validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static function hostname($hostname)
// maximum length is 253 characters, maximum segment size is 63

return
preg_match("/^([a-z\d](-*[a-z\d])*)(\.([a-z\d](-*[a-z\d])*))*\.?$/i", $hostname) //valid chars check
preg_match("/^([a-z\d](-*[a-z\d_])*)(\.([a-z\d](-*[a-z\d_])*))*\.?$/i", $hostname) //valid chars check
&& preg_match('/^.{1,253}$/', $hostname) //overall length check
&& preg_match("/^[^\.]{1,63}(\.[^\.]{1,63})*\.?$/", $hostname);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/CommonFunctionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function testIsValidHostname(): void
$this->assertTrue(Validate::hostname('www.averylargedomainthatdoesnotreallyexist.com'), 'www.averylargedomainthatdoesnotreallyexist.com');
$this->assertTrue(Validate::hostname('cont-ains.h-yph-en-s.com'), 'cont-ains.h-yph-en-s.com');
$this->assertTrue(Validate::hostname('cisco-3750x'), 'cisco-3750x');
$this->assertFalse(Validate::hostname('cisco_3750x'), 'cisco_3750x');
$this->assertTrue(Validate::hostname('cisco_3750x'), 'cisco_3750x');
$this->assertFalse(Validate::hostname('goo gle.com'), 'goo gle.com');
$this->assertFalse(Validate::hostname('google..com'), 'google..com');
$this->assertFalse(Validate::hostname('google.com '), 'google.com ');
Expand Down

0 comments on commit 66efd42

Please sign in to comment.