Skip to content

Commit

Permalink
Use Uri.parse instead of Utils.URI
Browse files Browse the repository at this point in the history
Utils.URI can be configured to use a different parser and return an object that "behaves like a URI". However, `opaque` is not available in other objects (e.g. Addressable::URI), so in this instance we need to use URI.

Fixes #1484
  • Loading branch information
iMacTia committed Jan 20, 2023
1 parent cc7e7bc commit 773e3fc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/faraday/connection.rb
Expand Up @@ -473,7 +473,7 @@ 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 Utils.URI(url.to_s).opaque
url = url.to_s.gsub(':', '%3A') if URI.parse(url.to_s).opaque
uri = url ? base + url : base
if params
uri.query = params.to_query(params_encoder || options.params_encoder)
Expand Down
15 changes: 15 additions & 0 deletions spec/faraday/connection_spec.rb
Expand Up @@ -310,6 +310,21 @@ def decode(params)
expect(uri.to_s).to eq('http://service.com/api/service%3Asearch?limit=400')
end
end

context 'with a custom `default_uri_parser`' do
let(:url) { 'http://httpbingo.org' }
let(:parser) { Addressable::URI }

around do |example|
with_default_uri_parser(parser) do
example.run
end
end

it 'does not raise error' do
expect { conn.build_exclusive_url('/nigiri') }.not_to raise_error
end
end
end

describe '#build_url' do
Expand Down

0 comments on commit 773e3fc

Please sign in to comment.