From 773e3fc87aafe93efe299246557d174cd2265daa Mon Sep 17 00:00:00 2001 From: Mattia Giuffrida Date: Fri, 20 Jan 2023 14:27:47 +0000 Subject: [PATCH] Use Uri.parse instead of Utils.URI 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 --- lib/faraday/connection.rb | 2 +- spec/faraday/connection_spec.rb | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/faraday/connection.rb b/lib/faraday/connection.rb index 9d694b70f..4a4a73c41 100644 --- a/lib/faraday/connection.rb +++ b/lib/faraday/connection.rb @@ -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) diff --git a/spec/faraday/connection_spec.rb b/spec/faraday/connection_spec.rb index 05d9c280b..d4ccb23d8 100644 --- a/spec/faraday/connection_spec.rb +++ b/spec/faraday/connection_spec.rb @@ -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