From 74930b1ccd9acacd1ddaa30d1b4849b0e4570d7c Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Sat, 12 Aug 2023 16:36:23 +0800 Subject: [PATCH] Avoiding accessing undefined mentionValues (#26461) The `window.config.mentionValues` might be undefined: ``` {{if or .Participants .Assignees .MentionableTeams}} mentionValues: ... {{end}} ``` --- web_src/js/features/tribute.js | 2 +- web_src/js/utils/match.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/web_src/js/features/tribute.js b/web_src/js/features/tribute.js index 43fa79b2a..055777be7 100644 --- a/web_src/js/features/tribute.js +++ b/web_src/js/features/tribute.js @@ -31,7 +31,7 @@ function makeCollections({mentions, emoji}) { if (mentions) { collections.push({ - values: window.config.mentionValues, + values: window.config.mentionValues ?? [], requireLeadingSpace: true, menuItemTemplate: (item) => { return ` diff --git a/web_src/js/utils/match.js b/web_src/js/utils/match.js index 029fec884..17fdfed11 100644 --- a/web_src/js/utils/match.js +++ b/web_src/js/utils/match.js @@ -32,7 +32,7 @@ export function matchMention(queryText) { // results is a map of weights, lower is better const results = new Map(); - for (const obj of window.config.mentionValues) { + for (const obj of window.config.mentionValues ?? []) { const index = obj.key.toLowerCase().indexOf(query); if (index === -1) continue; const existing = results.get(obj);