mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Handle malformed URLs in TopicEmbed.absolutize_urls.
This commit is contained in:
@@ -208,14 +208,24 @@ class TopicEmbed < ActiveRecord::Base
|
||||
fragment = Nokogiri::HTML5.fragment("<div>#{contents}</div>")
|
||||
fragment.css('a').each do |a|
|
||||
if a['href'].present?
|
||||
a['href'] = URI.join(prefix, a['href']).to_s
|
||||
begin
|
||||
a['href'] = URI.join(prefix, a['href']).to_s
|
||||
rescue URI::InvalidURIError
|
||||
# NOOP, URL is malformed
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
fragment.css('img').each do |a|
|
||||
if a['src'].present?
|
||||
a['src'] = URI.join(prefix, a['src']).to_s
|
||||
begin
|
||||
a['src'] = URI.join(prefix, a['src']).to_s
|
||||
rescue URI::InvalidURIError
|
||||
# NOOP, URL is malformed
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
fragment.at('div').inner_html
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user