Skip to content

Commit

Permalink
Merge pull request #2 from jcoene/jcoene/no-encode-uri
Browse files Browse the repository at this point in the history
Replace use of URI.encode
  • Loading branch information
jcoene committed Apr 17, 2021
2 parents 59acee0 + 0cd995e commit 89ee1c8
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ language: ruby
rvm:
- 2.3.4
- 2.4.1
- 2.5.9
- 2.7.3
- 3.0.1
2 changes: 1 addition & 1 deletion frenchy.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Gem::Specification.new do |spec|

spec.add_dependency "json"

spec.add_development_dependency "bundler", "~> 1.3"
spec.add_development_dependency "bundler"
spec.add_development_dependency "guard-rspec"
spec.add_development_dependency "rake"
spec.add_development_dependency "rspec"
Expand Down
5 changes: 1 addition & 4 deletions lib/frenchy/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,13 @@ def get(path, params)
private

def perform(method, path, params)
uri = URI(@host)
uri = URI(@host + path)
body = nil
headers = {
"User-Agent" => "Frenchy/#{Frenchy::VERSION}",
"Accept" => Frenchy.accept_header,
}.merge(@headers)

# Set the URI path
uri.path = URI.encode(path)

# Set request parameters
if params.any?
case method
Expand Down
2 changes: 1 addition & 1 deletion lib/frenchy/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def initialize(service, method, path, params={}, extras={})
end

params.delete(k)
path.sub!(pat, v)
path.sub!(pat, CGI.escape(v))
end

@service = service
Expand Down
6 changes: 6 additions & 0 deletions spec/lib/frenchy/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
expect(request.path).to eql("/v1/users/1234/md5something")
end

it "escapes path parameters but not query params" do
request = Frenchy::Request.new("service", "get", "/v1/users/:slug/:fullname", {"slug" => "big dog 20", "fullname" => "How Big Is He?", "division" => "How Big Is He, Really?"}, {})
expect(request.path).to eql("/v1/users/big+dog+20/How+Big+Is+He%3F")
expect(request.params).to eql({"division" => "How Big Is He, Really?"})
end

it "retains remaining parameters as query parameters" do
request = Frenchy::Request.new("service", "get", "/v1/users/:id", {"id" => 1234, "token" => "md5something"}, {})
expect(request.path).to eql("/v1/users/1234")
Expand Down

0 comments on commit 89ee1c8

Please sign in to comment.