Commit ee1833bff9946c0e2f62934d9ad27f78f3711093
1 parent
15e52777
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
Do not crash when parsing a invalid URI
Showing
1 changed file
with
6 additions
and
1 deletions
Show diff stats
app/models/article.rb
... | ... | @@ -730,7 +730,12 @@ class Article < ActiveRecord::Base |
730 | 730 | def body_images_paths |
731 | 731 | require 'uri' |
732 | 732 | Hpricot(self.body.to_s).search('img[@src]').collect do |i| |
733 | - (self.profile && self.profile.environment) ? URI.join(self.profile.environment.top_url, URI.escape(i.attributes['src'])).to_s : i.attributes['src'] | |
733 | + begin | |
734 | + (self.profile && self.profile.environment) ? URI.join(self.profile.environment.top_url, URI.escape(i.attributes['src'], '[|]')).to_s : i.attributes['src'] | |
735 | + rescue | |
736 | + # some uris are invalid but still visible on modern browsers (e.g.: uri with square brackets) | |
737 | + i.attributes['src'] | |
738 | + end | |
734 | 739 | end |
735 | 740 | end |
736 | 741 | ... | ... |