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