Skip to content

Commit d8bfca2

Browse files
authored
Merge relative url without escaping (#1569)
1 parent 4abafa5 commit d8bfca2

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

lib/faraday/connection.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,8 @@ def build_exclusive_url(url = nil, params = nil, params_encoder = nil)
473473
if url && !base.path.end_with?('/')
474474
base.path = "#{base.path}/" # ensure trailing slash
475475
end
476-
url = url.to_s.gsub(':', '%3A') if URI.parse(url.to_s).opaque
476+
# Ensure relative url will be parsed correctly (such as `service:search` )
477+
url = "./#{url}" if url.respond_to?(:start_with?) && !url.start_with?('http://', 'https://', '/', './', '../')
477478
uri = url ? base + url : base
478479
if params
479480
uri.query = params.to_query(params_encoder || options.params_encoder)

spec/faraday/connection_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,14 +300,14 @@ def decode(params)
300300
it 'joins url to base when used relative path' do
301301
conn = Faraday.new(url: url)
302302
uri = conn.build_exclusive_url('service:search?limit=400')
303-
expect(uri.to_s).to eq('http://service.com/service%3Asearch?limit=400')
303+
expect(uri.to_s).to eq('http://service.com/service:search?limit=400')
304304
end
305305

306306
it 'joins url to base when used with path prefix' do
307307
conn = Faraday.new(url: url)
308308
conn.path_prefix = '/api'
309309
uri = conn.build_exclusive_url('service:search?limit=400')
310-
expect(uri.to_s).to eq('http://service.com/api/service%3Asearch?limit=400')
310+
expect(uri.to_s).to eq('http://service.com/api/service:search?limit=400')
311311
end
312312
end
313313

0 commit comments

Comments
 (0)