diff --git a/app/helpers/articles_helper.rb b/app/helpers/articles_helper.rb index de8d8b560..dbbdb5732 100644 --- a/app/helpers/articles_helper.rb +++ b/app/helpers/articles_helper.rb @@ -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") diff --git a/spec/helpers/articles_helper_spec.rb b/spec/helpers/articles_helper_spec.rb index fbbc7d86f..6baa3ed75 100644 --- a/spec/helpers/articles_helper_spec.rb +++ b/spec/helpers/articles_helper_spec.rb @@ -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