Skip to content
Snippets Groups Projects
Unverified Commit 198ebcf5 authored by Denis Berezin's avatar Denis Berezin Committed by GitHub
Browse files

Fix Embedded dashboard parameters parse runtime error (#41545)

* Fix parameters parse

* Add e2e test

* Add e2e test
parent 9797a74c
No related branches found
No related tags found
No related merge requests found
......@@ -245,4 +245,16 @@ describe("scenarios > public > dashboard", () => {
assertDashboardFullWidth();
});
it("should render when a filter passed with value starting from '0' (metabase#41483)", () => {
cy.get("@dashboardId").then(id => {
visitPublicDashboard(id, {
params: { text: "002" },
});
});
cy.url().should("include", "text=002");
filterWidget().findByText("002").should("be.visible");
});
});
import querystring from "querystring";
import { safeJsonParse } from "metabase/lib/utils";
function parseQueryStringOptions(s) {
const options = querystring.parse(s);
......@@ -7,7 +9,7 @@ function parseQueryStringOptions(s) {
if (options[name] === "") {
options[name] = true;
} else if (/^(true|false|-?\d+(\.\d+)?)$/.test(options[name])) {
options[name] = JSON.parse(options[name]);
options[name] = safeJsonParse(options[name]);
}
}
......
......@@ -184,3 +184,16 @@ export function compareVersions(
}
export const isEEBuild = () => PLUGIN_IS_EE_BUILD.isEEBuild();
export const safeJsonParse = (value: string | null | undefined) => {
if (!value) {
return null;
}
try {
return JSON.parse(value);
} catch (e) {
console.error("Unable to parse JSON: ", value, e);
return null;
}
};
......@@ -70,6 +70,16 @@ describe("PublicDashboard", () => {
expect(firstTab).toHaveAttribute("aria-selected", "true");
});
it("should render when a filter passed with value starting from '0' (metabase#41483)", async () => {
// note: as all slugs this is ignored and we only use the id
await setup({
queryString: "?my-filter-value=01",
});
// should not throw runtime error and render dashboard content
expect(screen.getByText(DASHBOARD_TITLE)).toBeInTheDocument();
});
});
async function setup({
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment