From f18deddb59124eecc575c1d8a9aec7dae42d1a54 Mon Sep 17 00:00:00 2001 From: Kyoro Date: Mon, 6 Apr 2020 17:25:07 +0200 Subject: [PATCH] Add context menu entry sanitation (#1198) Fixes a bug where a context menu entry (auto-fill, copy password, etc.) would display incorrectly when it included an ampersand. --- src/background/main.background.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/background/main.background.ts b/src/background/main.background.ts index 51f6627373..894cfecd59 100644 --- a/src/background/main.background.ts +++ b/src/background/main.background.ts @@ -560,7 +560,7 @@ export default class MainBackground { id: 'autofill_' + idSuffix, parentId: 'autofill', contexts: ['all'], - title: title, + title: this.sanitizeContextMenuTitle(title), }); } @@ -570,7 +570,7 @@ export default class MainBackground { id: 'copy-username_' + idSuffix, parentId: 'copy-username', contexts: ['all'], - title: title, + title: this.sanitizeContextMenuTitle(title), }); } @@ -580,7 +580,7 @@ export default class MainBackground { id: 'copy-password_' + idSuffix, parentId: 'copy-password', contexts: ['all'], - title: title, + title: this.sanitizeContextMenuTitle(title), }); } @@ -590,11 +590,15 @@ export default class MainBackground { id: 'copy-totp_' + idSuffix, parentId: 'copy-totp', contexts: ['all'], - title: title, + title: this.sanitizeContextMenuTitle(title), }); } } + private sanitizeContextMenuTitle(title: string): string { + return title.replace(/&/g, '&&'); + } + private cleanupNotificationQueue() { for (let i = this.notificationQueue.length - 1; i >= 0; i--) { if (this.notificationQueue[i].expires < new Date()) {