From ffa04af78d4ecbb0e14e6e3f07b960cbb3e69d5c Mon Sep 17 00:00:00 2001 From: Thomas Powell Date: Tue, 3 Oct 2023 20:43:35 -0400 Subject: [PATCH] Linter for regex match? Signed-off-by: Thomas Powell --- lib/ohai/mixin/network_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ohai/mixin/network_helper.rb b/lib/ohai/mixin/network_helper.rb index 8d5757d08..202e9002b 100644 --- a/lib/ohai/mixin/network_helper.rb +++ b/lib/ohai/mixin/network_helper.rb @@ -41,7 +41,7 @@ def hex_to_dec_netmask(netmask) # Addrinfo#ip*? methods return true on AI_CANONNAME Addrinfo records that match # the ipv* scheme and #ip? always returns true unless a non tcp Addrinfo def ip?(hostname) - !!(canonname =~ Resolv::IPv4::Regex) || !!(canonname =~ Resolv::IPv6::Regex) + Resolv::IPv4::Regex.match?(hostname) || Resolv::IPv6::Regex.match?(hostname) end # This does a forward and reverse lookup on the hostname to return what should be @@ -65,7 +65,7 @@ def canonicalize_hostname(hostname) # However, we have found that Windows hosts that are not joined to a domain # can return a non-qualified hostname). # Use a '.' in the canonname as indicator of FQDN - return canonname if canonname =~ /\./ + return canonname if /\./.match?(canonname) # If we got a non-qualified name, then we do a standard reverse resolve # which, assuming DNS is working, will work around that windows bug