Commit 56f06eb9 authored by Aaron Tidwell's avatar Aaron Tidwell

escape all qs params

parent f2cb11ca
......@@ -92,11 +92,10 @@ Client.prototype.makeRequest = function(obj) {
const serialized = util.serializeToQSParams(obj);
path = versionPaths[this.options.get('version')] + (path ? path : '') + '.' + this.options.get('format') + '?' + serialized;
// create options for the https call
const options = {
hostname: 'api.challonge.com',
path: path,
path: encodeURI(path),
method: method,
headers: {
'Content-Length': 0 // server throws nginx error without a content-length
......
......@@ -215,7 +215,26 @@ describe('Client Class', () => {
expect(httpsMock.opts).toEqual({
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',
headers: {
'Content-Length': 0
......
......@@ -6,7 +6,7 @@ var client = challonge.createClient({
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({
tournament: {
......@@ -31,7 +31,7 @@ function update() {
url: tourneyName,
signupCap: 16,
tournamentType: 'double elimination',
description: 'some new description',
description: 'some new description扶摇ståleSÓLO独播',
acceptAttachments: true
},
......@@ -39,7 +39,7 @@ function update() {
if (err) { console.log(err); return; }
console.log(data);
pcreate('player1');
pcreate('player1扶摇ståleSÓLO独播');
}
});
}
......@@ -53,7 +53,7 @@ function pcreate(name) {
callback: function(err,data){
if (err) { console.log(err); return; }
console.log(data);
if (name === 'player1') {
if (name === 'player1扶摇ståleSÓLO独播') {
pcreate('player2');
} else {
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