Skip to content

Commit 5b2a36f

Browse files
committed
Added Network::Host::REGEX (closes #550).
1 parent 266452a commit 5b2a36f

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

lib/ronin/support/network/host.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ module Network
141141
#
142142
class Host
143143

144+
# A regular expression for matching host names.
145+
#
146+
# @since 1.2.0
147+
REGEX = /\A(?:(?:[a-zA-Z\d](?:[-a-zA-Z\d]*[a-zA-Z\d])?)\.)*(?:[a-zA-Z](?:[-a-zA-Z\d]*[a-zA-Z\d])?)\.?\z/
148+
144149
# The host name.
145150
#
146151
# @return [String]

spec/network/host_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,22 @@
1818

1919
subject { described_class.new(hostname) }
2020

21+
describe "REGEX" do
22+
subject { described_class::REGEX }
23+
24+
it "must match a local hostname" do
25+
expect(subject =~ 'localhost').to be_truthy
26+
end
27+
28+
it "must match a domain name" do
29+
expect(subject =~ 'example.com').to be_truthy
30+
end
31+
32+
it "must match a sub-domain name" do
33+
expect(subject =~ 'www.example.com').to be_truthy
34+
end
35+
end
36+
2137
describe "#initialize" do
2238
it "must set #name" do
2339
expect(subject.name).to eq(hostname)

0 commit comments

Comments
 (0)