fix: getQueryParamsFromString function updated to use URLSearchParams (#37559)
This commit is contained in:
parent
7612e4f14d
commit
7e13fcbe7f
12
app/client/src/utils/getQueryParamsObject.test.ts
Normal file
12
app/client/src/utils/getQueryParamsObject.test.ts
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
import { getQueryParamsFromString } from "./getQueryParamsObject";
|
||||||
|
|
||||||
|
describe("getQueryParamsObject test", () => {
|
||||||
|
it("Check whether getQueryParamsFromString returns object with input string containing new lines", () => {
|
||||||
|
const output = getQueryParamsFromString(
|
||||||
|
"branch=new&text=%3Cp%3EHello%3C%2Fp%3E%0A%3Cp%3EWorld!%3C%2Fp%3E",
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(output.text).toEqual("<p>Hello</p>\n<p>World!</p>");
|
||||||
|
expect(output.branch).toEqual("new");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
@ -8,14 +8,7 @@ export const getQueryParamsFromString = (search: string | undefined) => {
|
||||||
if (!search) return {};
|
if (!search) return {};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return JSON.parse(
|
return Object.fromEntries(new URLSearchParams(search).entries());
|
||||||
'{"' +
|
|
||||||
decodeURI(search)
|
|
||||||
.replace(/"/g, '\\"')
|
|
||||||
.replace(/&/g, '","')
|
|
||||||
.replace(/=/g, '":"') +
|
|
||||||
'"}',
|
|
||||||
);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log.error(e, "error parsing search string");
|
log.error(e, "error parsing search string");
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user