Skip to content

Commit

Permalink
Fixing missing escaping of slashes within URL parameters, closes #73
Browse files Browse the repository at this point in the history
  • Loading branch information
andyjeffries committed Jun 13, 2017
1 parent a98f404 commit 7de5543
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 1.3.35

Bugfix:

- Slashes in URL params are now escaped to %2F (thanks to davidtolsma for the bug report)

## 1.3.34

Feature:
Expand Down
2 changes: 1 addition & 1 deletion lib/flexirest/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def prepare_url
target = @get_params.delete(token.to_sym) || @post_params.delete(token.to_sym) || @get_params.delete(token.to_s) || @post_params.delete(token.to_s) || ""
# it's possible the URL path variable may not be part of the request, in that case, try to resolve it from the object attributes
target = @object._attributes[token.to_sym] || "" if target == ""
@url.gsub!(":#{token}", URI.escape(target.to_s))
@url.gsub!(":#{token}", URI.escape(target.to_s).gsub("/", "%2F"))
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/flexirest/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Flexirest
VERSION = "1.3.34"
VERSION = "1.3.35"
end
5 changes: 5 additions & 0 deletions spec/lib/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ class WhitelistedDateClient < Flexirest::Base
ExampleClient.find id:"foo bar"
end

it "should pass URL-encode URL parameters including slashes" do
expect_any_instance_of(Flexirest::Connection).to receive(:get).with("/foo%2Fbar", an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:'{"result":true}', response_headers:{})))
ExampleClient.find id:"foo/bar"
end

it "should accept an integer as the only parameter and use it as id" do
expect_any_instance_of(Flexirest::Connection).to receive(:get).with("/1234", an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:'{"result":true}', response_headers:{})))
ExampleClient.find(1234)
Expand Down

0 comments on commit 7de5543

Please sign in to comment.