Skip to content

Commit

Permalink
Merge pull request #62 from ifad/bugfix/squeeze-double-slashes
Browse files Browse the repository at this point in the history
Squeeze multiple slashes in URLs
  • Loading branch information
tagliala authored Sep 7, 2024
2 parents 27d3d28 + bd07aa2 commit 4205e06
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.byebug_history
/.bundle/
/.yardoc
/coverage/
Expand Down
2 changes: 1 addition & 1 deletion lib/hawk/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def request(method, path, options)
private

def build_url(path)
base.merge(path.sub(%r{^/}, '')).to_s
base.merge(path.delete_prefix('/').squeeze('/')).to_s
end

def response_handler(response)
Expand Down
2 changes: 1 addition & 1 deletion lib/hawk/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Hawk
VERSION = '2.0.0'
VERSION = '3.0.0'
end
10 changes: 10 additions & 0 deletions spec/basic_operations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ class Person < Hawk::Model::Base
}
end

describe '.get' do
it 'squeezes multiple slashes' do
stub_request(:GET, 'https://example.org/people/batch/id')
.with(headers: { 'User-Agent' => 'Foobar' })
.to_return(status: 200, body: [2].to_json, headers: {})

expect(Person.get('/batch///id')).to contain_exactly(2)
end
end

describe '.find(id)' do
specify do
stub_request(:GET, 'https://example.org/people/2')
Expand Down

0 comments on commit 4205e06

Please sign in to comment.