Skip to content

Commit

Permalink
Fixed badly anchored regular expression
Browse files Browse the repository at this point in the history
Fixes #661
  • Loading branch information
weppos committed Aug 5, 2024
1 parent 5191750 commit 8b153f9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ This project uses [Semantic Versioning 2.0.0](http://semver.org/).

## major

### Fixed

- Fixed badly anchored regular expression (GH-661)

### Changed

- Minimum Ruby version 3.0
Expand Down
2 changes: 1 addition & 1 deletion lib/whois/server/adapters/arpa.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def request(string)
# "192.in-addr.arpa" => "192.0.0.0"
# "in-addr.arpa" => "0.0.0.0"
def inaddr_to_ip(string)
raise ServerError, "Invalid .in-addr.arpa address" unless string.match?(/^([0-9]{1,3}\.?){0,4}in-addr\.arpa$/)
raise ServerError, "Invalid .in-addr.arpa address" unless string.match?(/\A([0-9]{1,3}\.?){0,4}in-addr\.arpa\z/)

a, b, c, d = string.scan(/[0-9]{1,3}\./).reverse
[a, b, c, d].map do |token|
Expand Down
13 changes: 11 additions & 2 deletions spec/whois/server/adapters/arpa_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,22 @@

describe "#lookup" do
it "returns the WHOIS record" do
response = "Whois Response"
server = described_class.new(*definition)
expect(Whois::Server::Adapters::Arin.query_handler).to receive(:call).with("n + 229.128.in-addr.arpa", "whois.arin.net", 43).and_return(response)
expect(Whois::Server::Adapters::Arin.query_handler).to receive(:call)
.with("n + 229.128.in-addr.arpa", "whois.arin.net", 43)
.and_return(response = "Whois Response")

record = server.lookup("229.128.in-addr.arpa")
expect(record.to_s).to eq(response)
expect(record.parts).to eq([Whois::Record::Part.new(body: response, host: "whois.arin.net")])
end

it "discards newlines" do
server = described_class.new(*definition)

expect do
server.lookup("229.128.in-addr.arpa\nextra")
end.to raise_error(Whois::ServerError, "Invalid .in-addr.arpa address")
end
end
end

0 comments on commit 8b153f9

Please sign in to comment.