diff --git a/lib/pact/hal/link.rb b/lib/pact/hal/link.rb index e8d19662..9414e8ee 100644 --- a/lib/pact/hal/link.rb +++ b/lib/pact/hal/link.rb @@ -56,7 +56,7 @@ def wrap_response(http_response) def expand_url(params, url) new_url = url params.each do | key, value | - new_url = new_url.gsub('{' + key.to_s + '}', value) + new_url = new_url.gsub('{' + key.to_s + '}', URI.escape(value)) end new_url end diff --git a/spec/lib/pact/hal/link_spec.rb b/spec/lib/pact/hal/link_spec.rb index c5df8f0b..0a482e09 100644 --- a/spec/lib/pact/hal/link_spec.rb +++ b/spec/lib/pact/hal/link_spec.rb @@ -98,6 +98,10 @@ module Hal it "returns a duplicate Link with the expanded href" do expect(subject.expand(bar: 'wiffle').href).to eq "http://foo/wiffle" end + + 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 end end end