Commit 8fba011d authored by Aaron Tidwell's avatar Aaron Tidwell Committed by GitHub

escape all qs params (#37)

parent f2cb11ca
...@@ -92,11 +92,10 @@ Client.prototype.makeRequest = function(obj) { ...@@ -92,11 +92,10 @@ Client.prototype.makeRequest = function(obj) {
const serialized = util.serializeToQSParams(obj); const serialized = util.serializeToQSParams(obj);
path = versionPaths[this.options.get('version')] + (path ? path : '') + '.' + this.options.get('format') + '?' + serialized; path = versionPaths[this.options.get('version')] + (path ? path : '') + '.' + this.options.get('format') + '?' + serialized;
// create options for the https call // create options for the https call
const options = { const options = {
hostname: 'api.challonge.com', hostname: 'api.challonge.com',
path: path, path: encodeURI(path),
method: method, method: method,
headers: { headers: {
'Content-Length': 0 // server throws nginx error without a content-length 'Content-Length': 0 // server throws nginx error without a content-length
......
...@@ -215,7 +215,26 @@ describe('Client Class', () => { ...@@ -215,7 +215,26 @@ describe('Client Class', () => {
expect(httpsMock.opts).toEqual({ expect(httpsMock.opts).toEqual({
hostname: 'api.challonge.com', hostname: 'api.challonge.com',
path: '/v1/tournaments/some/path.json?randomprop=thingie&some_property[another_property]=anotherthing&api_key=mykey&cache_bust=1', path: '/v1/tournaments/some/path.json?randomprop=thingie&some_property%5Banother_property%5D=anotherthing&api_key=mykey&cache_bust=1',
method: 'GET',
headers: {
'Content-Length': 0
}
});
});
it('should make a request with escaped data for extended characters', () => {
spyOn(Math, 'random').and.returnValue(1);
client.options.apiKey = 'mykey';
client.makeRequest({
path: '/some/path',
method: 'GET',
randomprop: '扶摇ståleSÓLO独播'
});
expect(httpsMock.opts).toEqual({
hostname: 'api.challonge.com',
path: '/v1/tournaments/some/path.json?randomprop=%E6%89%B6%E6%91%87st%C3%A5leS%C3%93LO%E7%8B%AC%E6%92%AD&api_key=mykey&cache_bust=1',
method: 'GET', method: 'GET',
headers: { headers: {
'Content-Length': 0 'Content-Length': 0
......
...@@ -6,7 +6,7 @@ var client = challonge.createClient({ ...@@ -6,7 +6,7 @@ var client = challonge.createClient({
version: 1, version: 1,
}); });
var tourneyName = 'new_api_test' + Math.floor(Math.random()*10000); var tourneyName = 'new_api_test扶摇ståleSÓLO独播' + Math.floor(Math.random()*10000);
client.tournaments.create({ client.tournaments.create({
tournament: { tournament: {
...@@ -31,7 +31,7 @@ function update() { ...@@ -31,7 +31,7 @@ function update() {
url: tourneyName, url: tourneyName,
signupCap: 16, signupCap: 16,
tournamentType: 'double elimination', tournamentType: 'double elimination',
description: 'some new description', description: 'some new description扶摇ståleSÓLO独播',
acceptAttachments: true acceptAttachments: true
}, },
...@@ -39,7 +39,7 @@ function update() { ...@@ -39,7 +39,7 @@ function update() {
if (err) { console.log(err); return; } if (err) { console.log(err); return; }
console.log(data); console.log(data);
pcreate('player1'); pcreate('player1扶摇ståleSÓLO独播');
} }
}); });
} }
...@@ -53,7 +53,7 @@ function pcreate(name) { ...@@ -53,7 +53,7 @@ function pcreate(name) {
callback: function(err,data){ callback: function(err,data){
if (err) { console.log(err); return; } if (err) { console.log(err); return; }
console.log(data); console.log(data);
if (name === 'player1') { if (name === 'player1扶摇ståleSÓLO独播') {
pcreate('player2'); pcreate('player2');
} else { } else {
start(); start();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment