Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Closes EMB-854 actually escape the single quote (#64323)

Sébastien1c18e1023a0f
diff --git a/enterprise/frontend/src/metabase-enterprise/embedding_iframe_sdk_setup/utils/embed-snippet.ts b/enterprise/frontend/src/metabase-enterprise/embedding_iframe_sdk_setup/utils/embed-snippet.ts
index f38e66f42a9..a617d7b2088 100644
--- a/enterprise/frontend/src/metabase-enterprise/embedding_iframe_sdk_setup/utils/embed-snippet.ts
+++ b/enterprise/frontend/src/metabase-enterprise/embedding_iframe_sdk_setup/utils/embed-snippet.ts
@@ -87,7 +87,7 @@ const toDashCase = (str: string): string =>
export const formatAttributeValue = (value: unknown): string => {
if (Array.isArray(value) || typeof value === "object") {
const jsonString = JSON.stringify(value);
- const escapedString = jsonString.replace(/'/g, "&39;");
+ const escapedString = jsonString.replace(/'/g, "'");
return `'${escapedString}'`;
}
diff --git a/enterprise/frontend/src/metabase-enterprise/embedding_iframe_sdk_setup/utils/embed-snippet.unit.spec.ts b/enterprise/frontend/src/metabase-enterprise/embedding_iframe_sdk_setup/utils/embed-snippet.unit.spec.ts
index 86c3930fc7f..ae7a0ea3623 100644
--- a/enterprise/frontend/src/metabase-enterprise/embedding_iframe_sdk_setup/utils/embed-snippet.unit.spec.ts
+++ b/enterprise/frontend/src/metabase-enterprise/embedding_iframe_sdk_setup/utils/embed-snippet.unit.spec.ts
@@ -23,19 +23,19 @@ describe("formatAttributeValue", () => {
it("should HTML escape single quotes in array and objects", () => {
expect(formatAttributeValue(["O'Reilly", "D'Angelo"])).toBe(
- `'["O&39;Reilly","D&39;Angelo"]'`,
+ `'["O'Reilly","D'Angelo"]'`,
);
expect(formatAttributeValue({ quote: "It's a test" })).toBe(
- `'{"quote":"It&39;s a test"}'`,
+ `'{"quote":"It's a test"}'`,
);
});
it("should HTML escape single quotes in nested arrays and objects", () => {
expect(
formatAttributeValue([{ name: "O'Reilly" }, { name: "D'Angelo" }]),
- ).toBe(`'[{"name":"O&39;Reilly"},{"name":"D&39;Angelo"}]'`);
+ ).toBe(`'[{"name":"O'Reilly"},{"name":"D'Angelo"}]'`);
expect(formatAttributeValue({ nested: { quote: "It's a test" } })).toBe(
- `'{"nested":{"quote":"It&39;s a test"}}'`,
+ `'{"nested":{"quote":"It's a test"}}'`,
);
});