From 217b21e38b5018b361a7e3ecfa2d435f076ef5d1 Mon Sep 17 00:00:00 2001 From: Moises Machado Date: Wed, 2 Sep 2009 15:40:24 -0300 Subject: [PATCH] ActionItem1229: added http:// in front of incomplete external links in link blocks --- app/models/link_list_block.rb | 7 ++++++- test/unit/link_list_block_test.rb | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/models/link_list_block.rb b/app/models/link_list_block.rb index a74a9bf..36f59da 100644 --- a/app/models/link_list_block.rb +++ b/app/models/link_list_block.rb @@ -55,11 +55,16 @@ class LinkListBlock < Block end def expand_address(address) - if owner.respond_to?(:identifier) + add = if owner.respond_to?(:identifier) address.gsub('{profile}', owner.identifier) else address end + if add !~ /^[a-z]+:\/\// && add !~ /^\// + 'http://' + add + else + add + end end def editable? diff --git a/test/unit/link_list_block_test.rb b/test/unit/link_list_block_test.rb index 1e92e1d..ee413fa 100644 --- a/test/unit/link_list_block_test.rb +++ b/test/unit/link_list_block_test.rb @@ -67,4 +67,11 @@ class LinkListBlockTest < ActiveSupport::TestCase assert_no_match /onclick/, l.link_html(l.links.first) end + should 'add http in front of incomplete external links' do + {'/local/link' => '/local/link', 'http://example.org' => 'http://example.org', 'example.org' => 'http://example.org'}.each do |input, output| + l = LinkListBlock.new(:links => [{:name => 'categ', :address => input}]) + assert_tag_in_string l.content, :tag => 'a', :attributes => {:href => output} + end + end + end -- libgit2 0.21.2