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

Squeeze multiple slashes in URLs #62

Merged
merged 1 commit into from
Sep 7, 2024
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
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