mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Updated url query param encoding to exctly match angular encoding
This commit is contained in:
parent
f3dc5381ee
commit
0975f816aa
@ -14,3 +14,12 @@ describe('toUrlParams', () => {
|
||||
expect(url).toBe('server=backend-01&hasSpace=has%20space&many=1&many=2&many=3&true&number=20&isNull=&isUndefined=');
|
||||
});
|
||||
});
|
||||
|
||||
describe('toUrlParams', () => {
|
||||
it('should encode the same way as angularjs', () => {
|
||||
const url = toUrlParams({
|
||||
server: ':@',
|
||||
});
|
||||
expect(url).toBe('server=:@');
|
||||
});
|
||||
});
|
||||
|
@ -84,7 +84,7 @@ export async function getExploreUrl(
|
||||
}
|
||||
|
||||
const exploreState = JSON.stringify(state);
|
||||
url = renderUrl('/explore', { state: exploreState });
|
||||
url = renderUrl('/explore', { left: exploreState });
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
@ -11,6 +11,16 @@ export function renderUrl(path: string, query: UrlQueryMap | undefined): string
|
||||
return path;
|
||||
}
|
||||
|
||||
export function encodeURIComponentAsAngularJS(val, pctEncodeSpaces) {
|
||||
return encodeURIComponent(val).
|
||||
replace(/%40/gi, '@').
|
||||
replace(/%3A/gi, ':').
|
||||
replace(/%24/g, '$').
|
||||
replace(/%2C/gi, ',').
|
||||
replace(/%3B/gi, ';').
|
||||
replace(/%20/g, (pctEncodeSpaces ? '%20' : '+'));
|
||||
}
|
||||
|
||||
export function toUrlParams(a) {
|
||||
const s = [];
|
||||
const rbracket = /\[\]$/;
|
||||
@ -22,9 +32,9 @@ export function toUrlParams(a) {
|
||||
const add = (k, v) => {
|
||||
v = typeof v === 'function' ? v() : v === null ? '' : v === undefined ? '' : v;
|
||||
if (typeof v !== 'boolean') {
|
||||
s[s.length] = encodeURIComponent(k) + '=' + encodeURIComponent(v);
|
||||
s[s.length] = encodeURIComponentAsAngularJS(k, true) + '=' + encodeURIComponentAsAngularJS(v, true);
|
||||
} else {
|
||||
s[s.length] = encodeURIComponent(k);
|
||||
s[s.length] = encodeURIComponentAsAngularJS(k, true);
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user