From 821238d0425cb47c141932242d5e7be35d81fbcd Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Wed, 13 Jun 2018 10:08:48 +1000 Subject: [PATCH] fix: correctly escape expanded URL in the HAL client --- lib/pact/hal/link.rb | 2 +- spec/lib/pact/hal/link_spec.rb | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) 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