Skip to content

Commit

Permalink
Added Network::Host::REGEX (closes #550).
Browse files Browse the repository at this point in the history
  • Loading branch information
postmodern committed Dec 10, 2024
1 parent 266452a commit 5b2a36f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/ronin/support/network/host.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ module Network
#
class Host

# A regular expression for matching host names.
#
# @since 1.2.0
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/

# The host name.
#
# @return [String]
Expand Down
16 changes: 16 additions & 0 deletions spec/network/host_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@

subject { described_class.new(hostname) }

describe "REGEX" do
subject { described_class::REGEX }

it "must match a local hostname" do
expect(subject =~ 'localhost').to be_truthy
end

it "must match a domain name" do
expect(subject =~ 'example.com').to be_truthy
end

it "must match a sub-domain name" do
expect(subject =~ 'www.example.com').to be_truthy
end
end

describe "#initialize" do
it "must set #name" do
expect(subject.name).to eq(hostname)
Expand Down

0 comments on commit 5b2a36f

Please sign in to comment.