Skip to content

Commit

Permalink
link_to_url escapes automatically.
Browse files Browse the repository at this point in the history
  • Loading branch information
hasimo committed Nov 22, 2010
1 parent 969002d commit 4aa38a0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/jpmobile/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def willcom_location_link_to(str,options={})
private
# 外部へのリンク
def link_to_url(str, url)
%{<a href="#{url}">#{str}</a>}.html_safe
%{<a href="#{url}">#{str.html_safe? ? str : ERB::Util.h(str)}</a>}.html_safe
end
end
end
5 changes: 4 additions & 1 deletion test/rails/overrides/spec/helpers/helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
it "docomo_guid_link_to が guid=ON を付けたリンクを生成すること" do
docomo_guid_link_to("STRING", :controller => "filter", :action => "rawdata").should == %{<a href="/filter/rawdata?guid=ON">STRING</a>}
end

it "docomo_guid_link_toがstrをhtml_safeかチェックし 自動的にhtml要素をエスケープする" do
docomo_guid_link_to("<>&", :controller => "filter", :action => "rawdata").should == %{<a href="/filter/rawdata?guid=ON">&lt;&gt;&amp;</a>}
docomo_guid_link_to("<>&".html_safe, :controller => "filter", :action => "rawdata").should == %{<a href="/filter/rawdata?guid=ON"><>&</a>}
end
it "softbank_location_link_to がリンク先にパラメータを含んでいても正常に動作すること" do
# http://d.hatena.ne.jp/mizincogrammer/20090123/1232702067
softbank_location_link_to("STRING", :controller => "filter", :action => "rawdata", :p => "param").should == %{<a href="location:auto?url=http://test.host/filter/rawdata&p=param">STRING</a>}
Expand Down

0 comments on commit 4aa38a0

Please sign in to comment.