Faraday::Connection#build_url doesnt add an ending slash to urls

This commit is contained in:
risk 2011-06-16 12:23:45 -04:00
parent 2ce28e9a81
commit e61e92b9ee
2 changed files with 10 additions and 1 deletions

View File

@ -217,7 +217,9 @@ module Faraday
def build_url(url, extra_params = nil)
uri = URI.parse(url.to_s)
if @path_prefix && uri.path !~ /^\//
uri.path = "#{@path_prefix.size > 1 ? @path_prefix : nil}/#{uri.path}"
new_path = @path_prefix.size > 1 ? @path_prefix.dup : ''
new_path << "/#{uri.path}" unless uri.path.empty?
uri.path = new_path
end
uri.host ||= @host
uri.port ||= @port

View File

@ -147,6 +147,13 @@ class TestConnection < Faraday::TestCase
assert_equal '/sake.html', uri.path
end
def test_build_url_doesnt_add_ending_slash
conn = Faraday::Connection.new
conn.url_prefix = "http://sushi.com/nigiri"
uri = conn.build_url(nil)
assert_equal "/nigiri", uri.path
end
def test_build_url_parses_url_params_into_query
conn = Faraday::Connection.new
uri = conn.build_url("http://sushi.com/sake.html", 'a[b]' => '1 + 2')