diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/sonar-web/src/main/js/helpers/request.js | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/server/sonar-web/src/main/js/helpers/request.js b/server/sonar-web/src/main/js/helpers/request.js index 8c80e71df44..941532e4b57 100644 --- a/server/sonar-web/src/main/js/helpers/request.js +++ b/server/sonar-web/src/main/js/helpers/request.js @@ -19,6 +19,7 @@ */ // @flow import { stringify } from 'querystring'; +import { omitBy, isNil } from 'lodash'; import { getCookie } from './cookies'; type Response = { @@ -50,6 +51,10 @@ export function getCSRFToken(): Object { return value ? { [getCSRFTokenName()]: value } : {}; } +export function omitNil(obj: Object): Object { + return omitBy(obj, isNil); +} + /** * Default options for any request */ @@ -96,12 +101,14 @@ class Request { if (this.data) { if (this.data instanceof FormData) { options.body = this.data; - } else if (options.method === 'GET') { - url += '?' + stringify(this.data); } else { - customHeaders['Content-Type'] = 'application/x-www-form-urlencoded'; - // $FlowFixMe complains that `data` is nullable - options.body = stringify(this.data); + const strData = stringify(omitNil(this.data)); + if (options.method === 'GET') { + url += '?' + strData; + } else { + customHeaders['Content-Type'] = 'application/x-www-form-urlencoded'; + options.body = strData; + } } } |