diff --git a/lib/pact/hal/link.rb b/lib/pact/hal/link.rb index 1fa272c2..24e8cafb 100644 --- a/lib/pact/hal/link.rb +++ b/lib/pact/hal/link.rb @@ -1,4 +1,4 @@ -require 'uri' +require 'erb' require 'delegate' module Pact @@ -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 diff --git a/spec/lib/pact/hal/link_spec.rb b/spec/lib/pact/hal/link_spec.rb index c81c9715..3b560904 100644 --- a/spec/lib/pact/hal/link_spec.rb +++ b/spec/lib/pact/hal/link_spec.rb @@ -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