mirror of
https://github.com/weaveworks/scope.git
synced 2026-03-03 18:20:27 +00:00
Merge pull request #1956 from weaveworks/1953-fix-query-string
Prevent querystrings from starting with &
This commit is contained in:
@@ -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');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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 '';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user