Sanitize URL before parsing (#17559)
URL strings that have leading or trailing spaces raise exceptions when parsing.
This commit is contained in:
parent
3fc6108651
commit
c568557ead
2 changed files with 6 additions and 0 deletions
|
|
@ -52,6 +52,7 @@ module ArticlesHelper
|
|||
end
|
||||
|
||||
def get_host_without_www(url)
|
||||
url = url.strip
|
||||
url = "http://#{url}" if Addressable::URI.parse(url).scheme.nil?
|
||||
host = Addressable::URI.parse(url).host.downcase
|
||||
host.gsub!("medium.com", "Medium")
|
||||
|
|
|
|||
|
|
@ -21,6 +21,11 @@ describe ArticlesHelper do
|
|||
host = helper.get_host_without_www("www.example.com")
|
||||
expect(host).to eq "example.com"
|
||||
end
|
||||
|
||||
it "can handle URLs with leading and trailing whitespace" do
|
||||
host = helper.get_host_without_www(" www.example.com ")
|
||||
expect(host).to eq "example.com"
|
||||
end
|
||||
end
|
||||
|
||||
describe "#image_tag_or_inline_svg_tag" do
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue