Commit 217b21e38b5018b361a7e3ecfa2d435f076ef5d1
Committed by
Antonio Terceiro
1 parent
0b907bbd
Exists in
master
and in
28 other branches
ActionItem1229: added http:// in front of incomplete external links in link blocks
Showing
2 changed files
with
13 additions
and
1 deletions
Show diff stats
app/models/link_list_block.rb
... | ... | @@ -55,11 +55,16 @@ class LinkListBlock < Block |
55 | 55 | end |
56 | 56 | |
57 | 57 | def expand_address(address) |
58 | - if owner.respond_to?(:identifier) | |
58 | + add = if owner.respond_to?(:identifier) | |
59 | 59 | address.gsub('{profile}', owner.identifier) |
60 | 60 | else |
61 | 61 | address |
62 | 62 | end |
63 | + if add !~ /^[a-z]+:\/\// && add !~ /^\// | |
64 | + 'http://' + add | |
65 | + else | |
66 | + add | |
67 | + end | |
63 | 68 | end |
64 | 69 | |
65 | 70 | def editable? | ... | ... |
test/unit/link_list_block_test.rb
... | ... | @@ -67,4 +67,11 @@ class LinkListBlockTest < ActiveSupport::TestCase |
67 | 67 | assert_no_match /onclick/, l.link_html(l.links.first) |
68 | 68 | end |
69 | 69 | |
70 | + should 'add http in front of incomplete external links' do | |
71 | + {'/local/link' => '/local/link', 'http://example.org' => 'http://example.org', 'example.org' => 'http://example.org'}.each do |input, output| | |
72 | + l = LinkListBlock.new(:links => [{:name => 'categ', :address => input}]) | |
73 | + assert_tag_in_string l.content, :tag => 'a', :attributes => {:href => output} | |
74 | + end | |
75 | + end | |
76 | + | |
70 | 77 | end | ... | ... |