Normalize URL from Feed Entry after adding link to original in Topic

Since a URL might be case sensitive, adding a link to the original
Feed Entry with changed case to the Topic could end in 404.
This commit is contained in:
Aslak Knutsen 2014-03-27 04:24:57 +01:00
parent ec1ea18877
commit f011fbdca9
2 changed files with 13 additions and 2 deletions

View File

@ -14,13 +14,13 @@ class TopicEmbed < ActiveRecord::Base
def self.import(user, url, title, contents)
return unless url =~ /^https?\:\/\//
url = normalize_url(url)
if SiteSetting.embed_truncate
contents = first_paragraph_from(contents)
end
contents << "\n<hr>\n<small>#{I18n.t('embed.imported_from', link: "<a href='#{url}'>#{url}</a>")}</small>\n"
url = normalize_url(url)
embed = TopicEmbed.where("lower(embed_url) = ?", url).first
content_sha1 = Digest::SHA1.hexdigest(contents)
post = nil

View File

@ -41,6 +41,17 @@ describe TopicEmbed do
post.cooked.should =~ /new contents/
end
it "Should leave uppercase Feed Entry URL untouched in content" do
cased_url = 'http://eviltrout.com/ABCD'
post = TopicEmbed.import(user, cased_url, title, "some random content")
post.cooked.should =~ /#{cased_url}/
end
it "Should leave lowercase Feed Entry URL untouched in content" do
cased_url = 'http://eviltrout.com/abcd'
post = TopicEmbed.import(user, cased_url, title, "some random content")
post.cooked.should =~ /#{cased_url}/
end
end
end