Revert "Update RFC1123 Hostname Check" (#7577)

* Revert "Revert "feature: Allow snmpget in os discovery yaml (#7558)" (#7576)"

This reverts commit 426916dbe47d31a38e042aad98915eb618c04760.

* Revert "fix: lldp find_port_id finds not the most correct port (#7564)"

This reverts commit 7e05fff615bb765262f2abde36219ea691ee7f99.

* Revert "fix: Update RFC1123 Hostname Check (#7572)"

This reverts commit ebcfa45a933991f35ece3a643a552e161a1825bf.
This commit is contained in:
Neil Lathwood
2017-10-29 20:05:59 +00:00
committed by GitHub
parent 426916dbe4
commit 3e94077a71
2 changed files with 2 additions and 7 deletions

View File

@ -629,9 +629,9 @@ function is_valid_hostname($hostname)
// maximum length is 253 characters, maximum segment size is 63
return (
preg_match("/^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])\.?$/", $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) //segment length check
&& preg_match("/^[^\.]{1,63}(\.[^\.]{1,63})*\.?$/", $hostname)
);
}

View File

@ -129,16 +129,11 @@ class CommonFunctionsTest extends \PHPUnit_Framework_TestCase
$this->assertTrue(is_valid_hostname('google.com'), 'google.com');
$this->assertTrue(is_valid_hostname('news.google.co.uk'), 'news.google.co.uk');
$this->assertTrue(is_valid_hostname('xn--fsqu00a.xn--0zwm56d'), 'xn--fsqu00a.xn--0zwm56d');
$this->assertTrue(is_valid_hostname('www.averylargedomainthatdoesnotreallyexist.com'), 'www.averylargedomainthatdoesnotreallyexist.com');
$this->assertTrue(is_valid_hostname('cont-ains.h-yph-en-s.com'), 'cont-ains.h-yph-en-s.com');
$this->assertTrue(is_valid_hostname('cisco-3750x'), 'cisco-3750x');
$this->assertFalse(is_valid_hostname('cisco_3750x'), 'cisco_3750x');
$this->assertFalse(is_valid_hostname('goo gle.com'), 'goo gle.com');
$this->assertFalse(is_valid_hostname('google..com'), 'google..com');
$this->assertFalse(is_valid_hostname('google.com '), 'google.com ');
$this->assertFalse(is_valid_hostname('google-.com'), 'google-.com');
$this->assertFalse(is_valid_hostname('.google.com'), '.google.com');
$this->assertFalse(is_valid_hostname('..google.com'), '..google.com');
$this->assertFalse(is_valid_hostname('<script'), '<script');
$this->assertFalse(is_valid_hostname('alert('), 'alert(');
$this->assertFalse(is_valid_hostname('.'), '.');