diff --git a/app/models/article.rb b/app/models/article.rb index 56e39cc..8106e9b 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -512,7 +512,7 @@ class Article < ActiveRecord::Base def body_images_paths require 'uri' Hpricot(self.body.to_s).search('img[@src]').collect do |i| - (self.profile && self.profile.environment) ? URI.join(self.profile.environment.top_url, i.attributes['src']).to_s : i.attributes['src'] + (self.profile && self.profile.environment) ? URI.join(self.profile.environment.top_url, URI.escape(i.attributes['src'])).to_s : i.attributes['src'] end end diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index bb31deb..a4cbf20 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -1555,4 +1555,11 @@ class ArticleTest < Test::Unit::TestCase assert_equal [], a.body_images_paths end + should 'survive to a invalid src attribute while looking for images in body' do + article = Article.new(:body => "An article with invalid src in img tag ", :profile => @profile) + assert_nothing_raised URI::InvalidURIError do + assert_equal ['http://localhost/path%20with%20spaces.png'], article.body_images_paths + end + end + end -- libgit2 0.21.2