Skip to content

Commit

Permalink
Merge pull request sporkmonger#337 from bbc/use-domain-when-setting-tld
Browse files Browse the repository at this point in the history
Use host when setting TLD
  • Loading branch information
sporkmonger committed Aug 31, 2019
2 parents d037e81 + a31b8ba commit e09e03b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/addressable/uri.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1182,7 +1182,7 @@ def tld
#
# @param [String, #to_str] new_tld The new top-level domain.
def tld=(new_tld)
replaced_tld = domain.sub(/#{tld}\z/, new_tld)
replaced_tld = host.sub(/#{tld}\z/, new_tld)
self.host = PublicSuffix::Domain.new(replaced_tld).to_s
end

Expand Down
6 changes: 3 additions & 3 deletions spec/addressable/uri_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5535,18 +5535,18 @@ def to_s
end

context "which " do
let (:uri) { Addressable::URI.parse("http://comrade.net/path/to/source/") }
let (:uri) { Addressable::URI.parse("http://www.comrade.net/path/to/source/") }

it "contains a subdomain" do
uri.tld = "co.uk"

expect(uri.to_s).to eq("http://comrade.co.uk/path/to/source/")
expect(uri.to_s).to eq("http://www.comrade.co.uk/path/to/source/")
end

it "is part of the domain" do
uri.tld = "com"

expect(uri.to_s).to eq("http://comrade.com/path/to/source/")
expect(uri.to_s).to eq("http://www.comrade.com/path/to/source/")
end
end
end
Expand Down

0 comments on commit e09e03b

Please sign in to comment.