From 416cffe52adc6c235d8ebb759a1fff2000ec4e38 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Mon, 27 May 2019 13:25:58 +0100 Subject: [PATCH] #577 fix bug related to hostnames comprised a-f only --- Build.PL | 1 + lib/App/Netdisco/DB/ResultSet/Device.pm | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Build.PL b/Build.PL index 1d79309b..3fb6f8c4 100644 --- a/Build.PL +++ b/Build.PL @@ -68,6 +68,7 @@ Module::Build->new( 'Plack::Middleware::Expires' => '0.03', 'Plack::Middleware::ReverseProxy' => '0.15', 'Pod::Usage' => 0, + 'Regexp::Common' => 2017060201, 'Role::Tiny' => '1.002005', 'Scope::Guard' => 0, 'Sereal' => '0', diff --git a/lib/App/Netdisco/DB/ResultSet/Device.pm b/lib/App/Netdisco/DB/ResultSet/Device.pm index 271eeda6..dda4e04a 100644 --- a/lib/App/Netdisco/DB/ResultSet/Device.pm +++ b/lib/App/Netdisco/DB/ResultSet/Device.pm @@ -5,7 +5,9 @@ use strict; use warnings; use Try::Tiny; +use Regexp::Common 'net'; use NetAddr::IP::Lite ':lower'; + require Dancer::Logger; =head1 ADDITIONAL METHODS @@ -84,7 +86,7 @@ sub search_aliases { # rough approximation of IP addresses (v4 in v6 not supported). # this helps us avoid triggering any DNS. - my $by_ip = ($q =~ m{^(?:[.0-9/]+|[:0-9a-f/]+)$}i) ? 1 : 0; + my $by_ip = ($q =~ m{^(?:$RE{net}{IPv4}|$RE{net}{IPv6})$}i) ? 1 : 0; my $clause; if ($by_ip) { @@ -132,7 +134,7 @@ Returns only the first result of any found devices =back -If not matching devices are found, C is returned. +If no matching devices are found, C is returned. =cut