Fix url util converting false into true (#37402)

A value of key-value pair is stripped for boolean values. While this is ok for `true`, it kind of inverts `false`
This commit is contained in:
Simon Podlipsky 2021-08-18 10:10:29 +02:00 committed by GitHub
parent c6356c5bba
commit 9900f2ed48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -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', () => {

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;
}
};