Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(dashboard): show an API key's name as text in its confirmation
Yudhi Armyndharis27bd4197f9dd
diff --git a/dashboard/src/pages/ApiKeys.test.ts b/dashboard/src/pages/ApiKeys.test.tsindex 682490e75..b654ac3db 100644--- a/dashboard/src/pages/ApiKeys.test.ts+++ b/dashboard/src/pages/ApiKeys.test.ts@@ -554,3 +554,19 @@ test('an expiry Save cannot convert ends in an error toast, not a silent no-op',await screen.findByText('Invalid time value');assert.deepEqual(updateBodies, []);});++// The name of a key is free text and is interpolated into the delete confirmation. A name carrying a+// styled tag became a real element with a string `style`, which React throws on, so the page went down.+test('deleting a key whose name carries markup shows the name as text', async () => {+ const { screen, fireEvent } = rtl;+ const name = '<strong style="font-size:50px">boom</strong>';+ keyList = [{ ...billingBot, name }];+ renderApiKeys();+ await screen.findByText('owa_k1ab****');++ fireEvent.click(screen.getByTitle('Delete'));++ const dialog = await screen.findByRole('dialog');+ assert.ok(dialog.textContent?.includes(name), 'the name was not shown as typed');+ assert.equal(dialog.querySelector('strong[style]'), null, 'the name became an element');+});diff --git a/dashboard/src/pages/ApiKeys.tsx b/dashboard/src/pages/ApiKeys.tsxindex 5c231a111..4f72c63ef 100644--- a/dashboard/src/pages/ApiKeys.tsx+++ b/dashboard/src/pages/ApiKeys.tsx@@ -780,6 +780,11 @@ export function ApiKeys() {}values={{ name: confirmAction.name }}components={{ strong: <strong /> }}+ // The key's name is free text. Without escaping, a name carrying markup became elements of the+ // message: a styled tag handed React a string for `style`, which throws and took the whole page+ // down. Escaped on interpolation and unescaped for display, it stays the text it was typed as.+ tOptions={{ interpolation: { escapeValue: true } }}+ shouldUnescape/></p></Modal>