Skip to content

Commit

Permalink
Always dup url_prefix in Connection#build_exclusive_url (#1288)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeyds committed Jun 24, 2021
1 parent 830b696 commit 4dd3689
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lib/faraday/connection.rb
Expand Up @@ -520,9 +520,8 @@ def build_request(method)
# @return [URI]
def build_exclusive_url(url = nil, params = nil, params_encoder = nil)
url = nil if url.respond_to?(:empty?) && url.empty?
base = url_prefix
base = url_prefix.dup
if url && base.path && base.path !~ %r{/$}
base = base.dup
base.path = "#{base.path}/" # ensure trailing slash
end
url = url && URI.parse(url.to_s).opaque ? url.to_s.gsub(':', '%3A') : url
Expand Down
7 changes: 7 additions & 0 deletions spec/faraday/connection_spec.rb
Expand Up @@ -253,6 +253,13 @@
expect(uri.path).to eq('/sake.html')
end

it 'always returns new URI instance' do
conn.url_prefix = 'http://sushi.com'
uri1 = conn.build_exclusive_url(nil)
uri2 = conn.build_exclusive_url(nil)
expect(uri1).not_to equal(uri2)
end

context 'with url_prefixed connection' do
let(:url) { 'http://sushi.com/sushi/' }

Expand Down

0 comments on commit 4dd3689

Please sign in to comment.