Skip to content

Commit

Permalink
Merge relative url without escaping (lostisland#1567)
Browse files Browse the repository at this point in the history
  • Loading branch information
ykrods committed Jun 18, 2024
1 parent 4abafa5 commit 621aeea
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/faraday/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
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)
Expand Down
4 changes: 2 additions & 2 deletions spec/faraday/connection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 621aeea

Please sign in to comment.