Skip to content

Commit

Permalink
fix: correct url encoding for expanded HAL links
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Nov 15, 2018
1 parent 47d3894 commit 4abfe7d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 3 additions & 5 deletions lib/pact/hal/link.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'uri'
require 'erb'
require 'delegate'

module Pact
Expand Down Expand Up @@ -54,11 +54,9 @@ def wrap_response(href, http_response)
end

def expand_url(params, url)
new_url = url
params.each do | key, value |
new_url = new_url.gsub('{' + key.to_s + '}', URI.escape(value))
params.inject(url) do | url, (key, value) |
url.gsub('{' + key.to_s + '}', ERB::Util.url_encode(value))
end
new_url
end
end
end
Expand Down
4 changes: 4 additions & 0 deletions spec/lib/pact/hal/link_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ module Hal
it "returns a duplicate Link with the expanded href with URL escaping" do
expect(subject.expand(bar: 'wiffle meep').href).to eq "http://foo/wiffle%20meep"
end

it "returns a duplicate Link with the expanded href with URL escaping for forward slashes" do
expect(subject.expand(bar: 'wiffle/meep').href).to eq "http://foo/wiffle%2Fmeep"
end
end
end
end
Expand Down

0 comments on commit 4abfe7d

Please sign in to comment.