mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
fix url query parser treating empty string as a number (#32825)
This commit is contained in:
parent
9efaa2c13f
commit
7c3a528d35
@ -40,6 +40,11 @@ describe('parseKeyValue', () => {
|
||||
expect(obj).toEqual({ num1: 12, num2: 12.2 });
|
||||
});
|
||||
|
||||
it('should not parse empty strinhg as number', () => {
|
||||
const obj = urlUtil.parseKeyValue('num1=&num2=12.2');
|
||||
expect(obj).toEqual({ num1: '', num2: 12.2 });
|
||||
});
|
||||
|
||||
it('should parse boolean params', () => {
|
||||
const obj = urlUtil.parseKeyValue('bool1&bool2=true&bool3=false');
|
||||
expect(obj).toEqual({ bool1: true, bool2: true, bool3: false });
|
||||
|
@ -155,7 +155,7 @@ export function parseKeyValue(keyValue: string) {
|
||||
val = val !== undefined ? tryDecodeURIComponent(val as string) : true;
|
||||
|
||||
let parsedVal: any;
|
||||
if (typeof val === 'string') {
|
||||
if (typeof val === 'string' && val !== '') {
|
||||
parsedVal = val === 'true' || val === 'false' ? val === 'true' : _.toNumber(val);
|
||||
} else {
|
||||
parsedVal = val;
|
||||
|
Loading…
Reference in New Issue
Block a user