diff --git a/lib/faraday/connection.rb b/lib/faraday/connection.rb index 6316fc93..e979e828 100644 --- a/lib/faraday/connection.rb +++ b/lib/faraday/connection.rb @@ -473,7 +473,8 @@ def build_exclusive_url(url = nil, params = nil, params_encoder = nil) if url && !base.path.end_with?('/') base.path = "#{base.path}/" # ensure trailing slash end - url = url.to_s.gsub(':', '%3A') if URI.parse(url.to_s).opaque + # Ensure relative url will be parsed correctly (such as `service:search` ) + url = "./#{url}" if url.respond_to?(:start_with?) && !url.start_with?('http://', 'https://', '/', './', '../') uri = url ? base + url : base if params uri.query = params.to_query(params_encoder || options.params_encoder) diff --git a/spec/faraday/connection_spec.rb b/spec/faraday/connection_spec.rb index d4ccb23d..7fa726a4 100644 --- a/spec/faraday/connection_spec.rb +++ b/spec/faraday/connection_spec.rb @@ -300,14 +300,14 @@ def decode(params) it 'joins url to base when used relative path' do conn = Faraday.new(url: url) uri = conn.build_exclusive_url('service:search?limit=400') - expect(uri.to_s).to eq('http://service.com/service%3Asearch?limit=400') + expect(uri.to_s).to eq('http://service.com/service:search?limit=400') end it 'joins url to base when used with path prefix' do conn = Faraday.new(url: url) conn.path_prefix = '/api' uri = conn.build_exclusive_url('service:search?limit=400') - expect(uri.to_s).to eq('http://service.com/api/service%3Asearch?limit=400') + expect(uri.to_s).to eq('http://service.com/api/service:search?limit=400') end end