Skip to content

Commit

Permalink
escape colon in path segment (#1237)
Browse files Browse the repository at this point in the history
  • Loading branch information
yarafan committed Jan 18, 2021
1 parent d22dd00 commit 0ed6480
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .rubocop_todo.yml
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
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
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

0 comments on commit 0ed6480

Please sign in to comment.