Created
September 5, 2008 15:28
-
-
Save koshigoe/8980 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: test/filter_test.rb | |
=================================================================== | |
--- test/filter_test.rb (リビジョン 18934) | |
+++ test/filter_test.rb (作業コピー) | |
@@ -7,8 +7,16 @@ | |
test 'filter a tag' do | |
term = flexmock("term") | |
term.should_receive(:get_carrier).and_return(SSB::KtaiSpec::CARRIER_DOCOMO) | |
- expected = %Q{<a href=\"./?ssb_q=http%3A%2F%2Fexample.com%3A80%2Fbar\" target=\"_top\">foo</a>} | |
- filtered = SSB::Application.filter_html("<a href='/bar'>foo</a>", URI.parse('http://example.com/foo'), term, '') | |
+ expected = %Q{<a href=\"./?ssb_q=http%3A%2F%2Fexample.com%3A80%2Fbar\" id='abc' target=\"_top\">foo</a>} | |
+ filtered = SSB::Application.filter_html("<a href='/bar' id='abc'>foo</a>", URI.parse('http://example.com/foo'), term, '') | |
assert_equal(expected, filtered) | |
end | |
+ | |
+ test 'filter a tag with absolute URI' do | |
+ term = flexmock("term") | |
+ term.should_receive(:get_carrier).and_return(SSB::KtaiSpec::CARRIER_DOCOMO) | |
+ expected = %Q{<a href=\"./?ssb_q=http%3A%2F%2Fwww.example.com%2F\" target=\"_top\">foo</a>} | |
+ filtered = SSB::Application.filter_html("<a href='http://www.example.com/'>foo</a>", URI.parse('http://example.com/foo'), term, '') | |
+ assert_equal(expected, filtered) | |
+ end | |
end | |
Index: libs/ssb.rb | |
=================================================================== | |
--- libs/ssb.rb (リビジョン 18934) | |
+++ libs/ssb.rb (作業コピー) | |
@@ -151,18 +151,21 @@ | |
begin | |
attribute = $1.downcase | |
value = $3 || $4 | |
+ other_attrs = $5 | |
case attribute | |
when 'src', 'data', 'href' | |
- case value[0,1] | |
- when '#' | |
- %Q! #{attribute}="#{value}"#{$5} target="_top">! | |
- when '/' | |
- %Q! #{attribute}="./?ssb_q=#{WEBrick::HTTPUtils.escape_form(('http://' + request_uri.host + ':' + request_uri.port.to_s + CGI.unescapeHTML(value)).to_s)}"#{$5} target="_top">! | |
+ case value | |
+ when /^https?:\/\// | |
+ %Q! #{attribute}="./?ssb_q=#{WEBrick::HTTPUtils.escape_form((CGI.unescapeHTML(value)).to_s)}"#{other_attrs} target="_top">! | |
+ when /^#/ | |
+ %Q! #{attribute}="#{value[0,1]}"#{other_attrs} target="_top">! | |
+ when /^\// | |
+ %Q! #{attribute}="./?ssb_q=#{WEBrick::HTTPUtils.escape_form(('http://' + request_uri.host + ':' + request_uri.port.to_s + CGI.unescapeHTML(value)).to_s)}"#{other_attrs} target="_top">! | |
else | |
- %Q! #{attribute}="./?ssb_q=#{WEBrick::HTTPUtils.escape_form((request_uri + CGI.escape(CGI.unescapeHTML(value))).to_s)}"#{$5} target="_top">! | |
+ %Q! #{attribute}="./?ssb_q=#{WEBrick::HTTPUtils.escape_form((request_uri + CGI.unescapeHTML(value)).to_s)}"#{other_attrs} target="_top">! | |
end | |
when 'action' | |
- %Q! #{attribute}="./" #{$5}><input type="hidden" name="ssb_q" value="#{(request_uri + value).to_s}" />! | |
+ %Q! #{attribute}="./" #{other_attrs}><input type="hidden" name="ssb_q" value="#{(request_uri + value).to_s}" />! | |
end | |
rescue => err | |
%Q! #{$1}=""! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment