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