Commit 23d69941ec2d295ed2a677e3d4b6a4909b3907f0
Committed by
Daniela Feitosa
1 parent
13061ed9
Exists in
master
and in
22 other branches
Escape URLs to avoid error when try to find image sources from article
(ActionItem2008)
Showing
2 changed files
with
8 additions
and
1 deletions
Show diff stats
app/models/article.rb
... | ... | @@ -512,7 +512,7 @@ class Article < ActiveRecord::Base |
512 | 512 | def body_images_paths |
513 | 513 | require 'uri' |
514 | 514 | Hpricot(self.body.to_s).search('img[@src]').collect do |i| |
515 | - (self.profile && self.profile.environment) ? URI.join(self.profile.environment.top_url, i.attributes['src']).to_s : i.attributes['src'] | |
515 | + (self.profile && self.profile.environment) ? URI.join(self.profile.environment.top_url, URI.escape(i.attributes['src'])).to_s : i.attributes['src'] | |
516 | 516 | end |
517 | 517 | end |
518 | 518 | ... | ... |
test/unit/article_test.rb
... | ... | @@ -1555,4 +1555,11 @@ class ArticleTest < Test::Unit::TestCase |
1555 | 1555 | assert_equal [], a.body_images_paths |
1556 | 1556 | end |
1557 | 1557 | |
1558 | + should 'survive to a invalid src attribute while looking for images in body' do | |
1559 | + article = Article.new(:body => "An article with invalid src in img tag <img src='path with spaces.png' />", :profile => @profile) | |
1560 | + assert_nothing_raised URI::InvalidURIError do | |
1561 | + assert_equal ['http://localhost/path%20with%20spaces.png'], article.body_images_paths | |
1562 | + end | |
1563 | + end | |
1564 | + | |
1558 | 1565 | end | ... | ... |