Commit 86d3871e2cbae356f6542b5255b98bcb33ee5e41

Authored by Daniel Cunha
Committed by Antonio Terceiro
1 parent 2b9d5ed9

Fixing problem of comments with long URL that overflow the content area

(ActionItem1686)
app/helpers/display_helper.rb
@@ -31,9 +31,10 @@ module DisplayHelper @@ -31,9 +31,10 @@ module DisplayHelper
31 gsub( /\n\s*\n/, ' <p/> ' ). 31 gsub( /\n\s*\n/, ' <p/> ' ).
32 gsub( /\n/, ' <br/> ' ). 32 gsub( /\n/, ' <br/> ' ).
33 gsub( /(^|\s)(www\.[^\s])/, '\1http://\2' ). 33 gsub( /(^|\s)(www\.[^\s])/, '\1http://\2' ).
34 - gsub( /(https?:\/\/([^\s]+))/,  
35 - '<a href="\1" target="_blank" rel="nofolow" onclick="return confirm(\'' +  
36 - escape_javascript( _('Are you sure you want to visit this web site?') ) +  
37 - '\n\n\'+this.href)">\2</a>' ) 34 + gsub( /(https?:\/\/([^\s]+))/ ) do
  35 + href, content = $1, $2.scan(/.{4}/).join('&#x200B;')
  36 + content_tag(:a, content, :href => href, :target => '_blank', :rel => 'nofolow',
  37 + :onclick => "return confirm('%s')" % escape_javascript(_('Are you sure you want to visit this web site?')))
  38 + end
38 end 39 end
39 end 40 end
test/functional/catalog_controller_test.rb
@@ -80,4 +80,11 @@ class CatalogControllerTest &lt; Test::Unit::TestCase @@ -80,4 +80,11 @@ class CatalogControllerTest &lt; Test::Unit::TestCase
80 assert_tag :tag => 'a', :attributes => {:href => /assets\/products\?product_category=#{pc.id}/} 80 assert_tag :tag => 'a', :attributes => {:href => /assets\/products\?product_category=#{pc.id}/}
81 end 81 end
82 82
  83 + should 'add an zero width space every 4 caracters of comment urls' do
  84 + url = 'www.an.url.to.be.splited.com'
  85 + prod = @enterprise.products.create!(:name => 'Product test', :price => 50.00, :product_category => @product_category, :description => url)
  86 + get :index, :profile => @enterprise.identifier
  87 + assert_tag :a, :attributes => { :href => "http://" + url}, :content => url.scan(/.{4}/).join('&#x200B;')
  88 + end
  89 +
83 end 90 end
test/functional/content_viewer_controller_test.rb
@@ -1245,4 +1245,12 @@ class ContentViewerControllerTest &lt; Test::Unit::TestCase @@ -1245,4 +1245,12 @@ class ContentViewerControllerTest &lt; Test::Unit::TestCase
1245 assert_redirected_to :profile => @profile.identifier, :page => page.explode_path 1245 assert_redirected_to :profile => @profile.identifier, :page => page.explode_path
1246 end 1246 end
1247 1247
  1248 + should 'add an zero width space every 4 caracters of comment urls' do
  1249 + url = 'www.an.url.to.be.splited.com'
  1250 + a = fast_create(TextileArticle, :profile_id => @profile.id, :path => 'textile', :language => 'en')
  1251 + c = a.comments.create!(:author => @profile, :title => 'An url', :body => url)
  1252 + get :view_page, :profile => @profile.identifier, :page => [ 'textile' ]
  1253 + assert_tag :a, :attributes => { :href => "http://" + url}, :content => url.scan(/.{4}/).join('&#x200B;')
  1254 + end
  1255 +
1248 end 1256 end