Skip to content

Commit 45d09df

Browse files
committed
Added Network::URL#defang (closes #545).
1 parent 1ebc55d commit 45d09df

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

lib/ronin/support/network/url.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#
1818

1919
require 'ronin/support/network/http'
20+
require 'ronin/support/network/defang'
2021

2122
require 'addressable/uri'
2223
require 'uri/query_params/core_ext/addressable/uri'
@@ -37,6 +38,21 @@ module Network
3738
#
3839
class URL < Addressable::URI
3940

41+
#
42+
# Defangs the URL.
43+
#
44+
# @return [String]
45+
# The defanged URL.
46+
#
47+
# @example
48+
# url = URL.new("https://www.example.com:8080/foo?q=1")
49+
# url.defang
50+
# # => "hxxps[://]www[.]example[.]com[:]8080/foo?q=1"
51+
#
52+
def defang
53+
Defang.defang_url(self)
54+
end
55+
4056
#
4157
# Returns the Status Code of the HTTP Response for the URL.
4258
#

spec/network/url_spec.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,18 @@
1212
expect(described_class).to include(URI::QueryParams::Mixin)
1313
end
1414

15-
subject { described_class.parse('https://example.com/') }
15+
let(:url) { 'https://example.com/' }
16+
17+
subject { described_class.parse(url) }
18+
19+
describe "#defang" do
20+
let(:url) { 'http://www.example.com/foo?q=1' }
21+
let(:defanged) { 'hxxp[://]www[.]example[.]com/foo?q=1' }
22+
23+
it "must return the defanged URL" do
24+
expect(subject.defang).to eq(defanged)
25+
end
26+
end
1627

1728
describe "#status" do
1829
context "integration", :network do

0 commit comments

Comments
 (0)