Prevent querystrings from starting with &

Fixes #1953
This commit is contained in:
David Kaltschmidt
2016-10-27 16:02:25 +02:00
parent 590f0078e7
commit 60037c8c7c
2 changed files with 19 additions and 2 deletions

View File

@@ -1,5 +1,7 @@
jest.dontMock('../web-api-utils');
import {OrderedMap as makeOrderedMap} from 'immutable';
describe('WebApiUtils', () => {
const WebApiUtils = require('../web-api-utils');
@@ -22,4 +24,19 @@ describe('WebApiUtils', () => {
expect(basePath('/')).toBe('');
});
});
describe('buildOptionsQuery', () => {
const buildOptionsQuery = WebApiUtils.buildOptionsQuery;
it('should handle empty options', () => {
expect(buildOptionsQuery(makeOrderedMap({}))).toBe('');
});
it('should combine multiple options', () => {
expect(buildOptionsQuery(makeOrderedMap([
['foo', 2],
['bar', 4]
]))).toBe('foo=2&bar=4');
});
});
});

View File

@@ -25,9 +25,9 @@ let controlErrorTimer = 0;
let createWebsocketAt = 0;
let firstMessageOnWebsocketAt = 0;
function buildOptionsQuery(options) {
export function buildOptionsQuery(options) {
if (options) {
return options.reduce((query, value, param) => `${query}&${param}=${value}`, '');
return options.map((value, param) => `${param}=${value}`).join('&');
}
return '';
}