-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
URL-encode param values in GET query strings (#41)
* URL-encode param values in GET query strings Commit 00b6b67 (tag: v0.1.12) "Fix request helper for get requests to build URI based on how API expects it" attempted to solve some unclearly-indentified problem with encoding the query string in GET-based API calls. The commit leaves param values unencoded/as-is instead of URL-encoding them. Unfortunately, that causes a regression in that param values containing spaces lead to the error "EOFError: end of file reached". I'm not sure what regressions we will cause by _reverting_ 00b6b67, but _that_ implementation is clearly broken. * Remove support for the bogus im.counters?username= param The `/api/v1/im.counters` endpoint does not support such a parameter. * Do not pass `nil` param values to the RC API endpoints * Add support for the optional im.counters?userId= param Refactor all im.counters tests * Add specs for RequestHelper#create_request
- Loading branch information
Showing
6 changed files
with
110 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
describe RocketChat::RequestHelper do | ||
describe '#create_request' do | ||
let(:including_class) { Class.new { include RocketChat::RequestHelper } } | ||
let(:instance) { including_class.new } | ||
|
||
describe 'URI-encoding' do | ||
subject(:req) { instance.send(:create_request, '/api/endpoint', body: request_params) } | ||
|
||
context 'when encoding multiple, simple parameters' do | ||
let(:request_params) { { foo: 1, bar: 'string' } } | ||
|
||
it 'URI-encodes each of them into the query string' do | ||
expect(req.path).to end_with('?foo=1&bar=string') | ||
end | ||
end | ||
|
||
context 'when encoding parameters containing spaces, ampersands, and other specials' do | ||
let(:request_params) { { foo: 'This & That', bar: '+ Plusses, too, with 98% success!' } } | ||
|
||
it 'URI-encodes them properly into the query string' do | ||
expect(req.path).to end_with('?foo=This+%26+That&bar=%2B+Plusses%2C+too%2C+with+98%25+success%21') | ||
end | ||
end | ||
|
||
context 'when encoding empty strings and nil parameters' do | ||
let(:request_params) { { empty: '', null: nil } } | ||
|
||
it 'preserves empty strings but drops nils from the query string' do | ||
expect(req.path).to end_with('?empty=') | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters