summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2020-10-30 12:16:45 -0700
committerTim Smith <tsmith84@gmail.com>2020-10-30 12:16:45 -0700
commitd8b9232adf761155c1529781e278f3cff93fa5dc (patch)
tree150c3c51213f798d55ef838c14420278ef439b8c
parent7b700df35ec1d884ac6507016bf2319d70dffa36 (diff)
downloadohai-simplify_regex.tar.gz
Simplify regexes by removing extra character classessimplify_regex
We're working harder here than we need to. Let's simplify these and make them easier to figure out for the humans involved. Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/ohai/plugins/aix/network.rb2
-rw-r--r--lib/ohai/plugins/aix/uptime.rb4
-rw-r--r--lib/ohai/plugins/kernel.rb2
-rw-r--r--lib/ohai/plugins/windows/network.rb2
-rw-r--r--spec/functional/plugins/powershell_spec.rb2
5 files changed, 6 insertions, 6 deletions
diff --git a/lib/ohai/plugins/aix/network.rb b/lib/ohai/plugins/aix/network.rb
index ef5c771d..9a24ebab 100644
--- a/lib/ohai/plugins/aix/network.rb
+++ b/lib/ohai/plugins/aix/network.rb
@@ -92,7 +92,7 @@ Ohai.plugin(:Network) do
if lin =~ /broadcast\s(\S+)\s/
iface[interface][:addresses][tmp_addr][:broadcast] = $1
end
- elsif lin =~ %r{inet6 ([a-f0-9\:]+)%?([\d]*)/?(\d*)?}
+ elsif lin =~ %r{inet6 ([a-f0-9\:]+)%?(\d*)/?(\d*)?}
# TODO do we have more properties on inet6 in aix? broadcast
iface[interface][:addresses] ||= Mash.new
iface[interface][:addresses][$1] = { "family" => "inet6", "zone_index" => $2, "prefixlen" => $3 }
diff --git a/lib/ohai/plugins/aix/uptime.rb b/lib/ohai/plugins/aix/uptime.rb
index 08cae057..b85a290e 100644
--- a/lib/ohai/plugins/aix/uptime.rb
+++ b/lib/ohai/plugins/aix/uptime.rb
@@ -40,9 +40,9 @@ Ohai.plugin(:Uptime) do
when /^\d+-\d/
(d, h, m, s) = so.split(/[-:]/)
when /^\d+:\d+:\d/
- (h, m, s) = so.split(/[:]/)
+ (h, m, s) = so.split(/:/)
else
- (m, s) = so.split(/[:]/)
+ (m, s) = so.split(/:/)
end
elapsed_seconds = ((d.to_i * 86400) + (h.to_i * 3600) + (m.to_i * 60) + s.to_i)
diff --git a/lib/ohai/plugins/kernel.rb b/lib/ohai/plugins/kernel.rb
index 19936364..2ec841df 100644
--- a/lib/ohai/plugins/kernel.rb
+++ b/lib/ohai/plugins/kernel.rb
@@ -244,7 +244,7 @@ Ohai.plugin(:Kernel) do
# EXAMPLE:
# Id Loadaddr Size Info Rev Module Name
# 6 1180000 4623 1 1 specfs (filesystem for specfs)
- module_description = /[\s]*([\d]+)[\s]+([a-f\d]+)[\s]+([a-f\d]+)[\s]+(?:[\-\d]+)[\s]+(?:[\d]+)[\s]+([\S]+)[\s]+\((.+)\)$/
+ module_description = /\s*(\d+)\s+([a-f\d]+)\s+([a-f\d]+)\s+(?:[\-\d]+)\s+(?:\d+)\s+(\S+)\s+\((.+)\)$/
so.stdout.lines do |line|
if ( mod = module_description.match(line) )
modules[mod[4]] = { id: mod[1].to_i, loadaddr: mod[2], size: mod[3].to_i(16), description: mod[5] }
diff --git a/lib/ohai/plugins/windows/network.rb b/lib/ohai/plugins/windows/network.rb
index 4efa4bcd..f2a9eb32 100644
--- a/lib/ohai/plugins/windows/network.rb
+++ b/lib/ohai/plugins/windows/network.rb
@@ -205,7 +205,7 @@ Ohai.plugin(:Network) do
so = shell_out("arp -a")
if so.exitstatus == 0
so.stdout.lines do |line|
- if line =~ /^Interface:\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s+[-]+\s+(0x\S+)/
+ if line =~ /^Interface:\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s+-+\s+(0x\S+)/
cint = $2.downcase
end
next unless iface[cint]
diff --git a/spec/functional/plugins/powershell_spec.rb b/spec/functional/plugins/powershell_spec.rb
index 16df35a6..b9e99c5d 100644
--- a/spec/functional/plugins/powershell_spec.rb
+++ b/spec/functional/plugins/powershell_spec.rb
@@ -19,7 +19,7 @@
require "spec_helper"
describe Ohai::System, "languages plugin" do
- VERSION_MATCHING_REGEX = /^(?:[\d]+\.)+[\d]+$/.freeze
+ VERSION_MATCHING_REGEX = /^(?:\d+\.)+\d+$/.freeze
describe "powershell plugin", :windows_only do
RSpec.shared_examples "a version looking thing" do
it "is present" do