提交 a0757e00 编写于 作者: S Stephen Celis 提交者: Santiago Pastorino

Protocol-relative URL support.

[#5774 state:committed]
Signed-off-by: NSantiago Pastorino <santiago@wyeworks.com>
上级 a96a9a49
......@@ -28,8 +28,11 @@ def url_for(options = {})
rewritten_url = ""
unless options[:only_path]
rewritten_url << (options[:protocol] || "http")
rewritten_url << "://" unless rewritten_url.match("://")
unless options[:protocol] == false
rewritten_url << (options[:protocol] || "http")
rewritten_url << ":" unless rewritten_url.match(%r{:|//})
end
rewritten_url << "//" unless rewritten_url.match("//")
rewritten_url << rewrite_authentication(options)
rewritten_url << host_or_subdomain_and_domain(options)
rewritten_url << ":#{options.delete(:port)}" if options[:port]
......
......@@ -95,16 +95,29 @@ def test_protocol
)
end
def test_protocol_with_and_without_separator
def test_protocol_with_and_without_separators
add_host!
assert_equal('https://www.basecamphq.com/c/a/i',
W.new.url_for(:controller => 'c', :action => 'a', :id => 'i', :protocol => 'https')
)
assert_equal('https://www.basecamphq.com/c/a/i',
W.new.url_for(:controller => 'c', :action => 'a', :id => 'i', :protocol => 'https:')
)
assert_equal('https://www.basecamphq.com/c/a/i',
W.new.url_for(:controller => 'c', :action => 'a', :id => 'i', :protocol => 'https://')
)
end
def test_without_protocol
add_host!
assert_equal('//www.basecamphq.com/c/a/i',
W.new.url_for(:controller => 'c', :action => 'a', :id => 'i', :protocol => '//')
)
assert_equal('//www.basecamphq.com/c/a/i',
W.new.url_for(:controller => 'c', :action => 'a', :id => 'i', :protocol => false)
)
end
def test_trailing_slash
add_host!
options = {:controller => 'foo', :trailing_slash => true, :action => 'bar', :id => '33'}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册