Skip to content

Commit

Permalink
Fix Embedded dashboard parameters parse runtime error (#41545)
Browse files Browse the repository at this point in the history
* Fix parameters parse

* Add e2e test

* Add e2e test
  • Loading branch information
deniskaber authored and Metabase bot committed Apr 18, 2024
1 parent dd1b41a commit 9f88571
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
12 changes: 12 additions & 0 deletions e2e/test/scenarios/sharing/public-dashboard.cy.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
});
4 changes: 3 additions & 1 deletion frontend/src/metabase/lib/browser.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import querystring from "querystring";

import { safeJsonParse } from "metabase/lib/utils";

function parseQueryStringOptions(s) {
const options = querystring.parse(s);

for (const name in options) {
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]);
}
}

Expand Down
13 changes: 13 additions & 0 deletions frontend/src/metabase/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,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;
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit 9f88571

Please sign in to comment.