mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
fix: Update RFC1123 Hostname Check (#7572)
* Update RFC1123 Hostname Check The regex was wrong. It failed to match devices like `cisco-3750x` even though it is a valid hostname. I picked this regex from the RFC1123 documentation, and updated it. * Update CommonFunctionsTest.php Update tests * Updated to allow domains ending with a dot
This commit is contained in:
committed by
Daniel Preussker
parent
6fab5166c5
commit
ebcfa45a93
@@ -629,9 +629,9 @@ function is_valid_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-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("/^.{1,253}$/", $hostname) //overall length check
|
||||
&& preg_match("/^[^\.]{1,63}(\.[^\.]{1,63})*\.?$/", $hostname)
|
||||
&& preg_match("/^[^\.]{1,63}(\.[^\.]{1,63})*\.?$/", $hostname) //segment length check
|
||||
);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user