FIX: Skip absolutizing URLs when source URI is invalid

This commit is contained in:
Penar Musaraj
2020-02-07 10:54:24 -05:00
parent 88a4d5a2c1
commit 99fd65328c
2 changed files with 15 additions and 1 deletions

View File

@ -186,7 +186,11 @@ class TopicEmbed < ActiveRecord::Base
# Convert any relative URLs to absolute. RSS is annoying for this.
def self.absolutize_urls(url, contents)
url = normalize_url(url)
uri = URI(UrlHelper.escape_uri(url))
begin
uri = URI(UrlHelper.escape_uri(url))
rescue URI::Error
return contents
end
prefix = "#{uri.scheme}://#{uri.host}"
prefix << ":#{uri.port}" if uri.port != 80 && uri.port != 443