Fix url util converting false into true (#37402) (#37997)

A value of key-value pair is stripped for boolean values. While this is ok for `true`, it kind of inverts `false`

(cherry picked from commit 9900f2ed48)

Co-authored-by: Simon Podlipsky <simon@podlipsky.net>
This commit is contained in:
Grot (@grafanabot)
2021-08-18 10:43:21 +02:00
committed by GitHub
co-authored by Simon Podlipsky
parent 1fe8b3a7b0
commit ab43bcf08a
2 changed files with 10 additions and 1 deletions
@@ -22,6 +22,14 @@ describe('toUrlParams', () => {
});
expect(url).toBe('server=:@');
});
it('should keep booleans', () => {
const url = urlUtil.toUrlParams({
bool1: true,
bool2: false,
});
expect(url).toBe('bool1&bool2=false');
});
});
describe('parseKeyValue', () => {
+2 -1
View File
@@ -48,7 +48,8 @@ function toUrlParams(a: any) {
if (typeof v !== 'boolean') {
s[s.length] = encodeURIComponentAsAngularJS(k, true) + '=' + encodeURIComponentAsAngularJS(v, true);
} else {
s[s.length] = encodeURIComponentAsAngularJS(k, true);
const valueQueryPart = v ? '' : '=' + encodeURIComponentAsAngularJS('false', true);
s[s.length] = encodeURIComponentAsAngularJS(k, true) + valueQueryPart;
}
};