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

escape colon in path segment #1237

Merged
merged 5 commits into from
Jan 18, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Metrics/AbcSize:
# Offense count: 4
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 234
Max: 235

# Offense count: 17
Metrics/CyclomaticComplexity:
Expand Down
1 change: 1 addition & 0 deletions lib/faraday/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ def build_exclusive_url(url = nil, params = nil, params_encoder = nil)
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
uri = url ? base + url : base
if params
uri.query = params.to_query(params_encoder || options.params_encoder)
Expand Down
23 changes: 23 additions & 0 deletions spec/faraday/connection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,29 @@
expect(uri.to_s).to eq('http://sushi.com/sake/')
end
end

context 'with colon in path' do
let(:url) { 'http://service.com' }

it 'joins url to base when used absolute 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:search?limit=400')
end

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')
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')
end
end
end

describe '#build_url' do
Expand Down