Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always dup url_prefix in Connection#build_exclusive_url #1288

Merged
merged 1 commit into from Jun 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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