]> source.dussan.org Git - gitea.git/commitdiff
Avoiding accessing undefined mentionValues (#26461)
authorwxiaoguang <wxiaoguang@gmail.com>
Sat, 12 Aug 2023 08:36:23 +0000 (16:36 +0800)
committerGitHub <noreply@github.com>
Sat, 12 Aug 2023 08:36:23 +0000 (08:36 +0000)
The `window.config.mentionValues` might be undefined:

```
{{if or .Participants .Assignees .MentionableTeams}}
    mentionValues: ...
{{end}}
```

web_src/js/features/tribute.js
web_src/js/utils/match.js

index 43fa79b2a4dce9bad3118618f095f7cdf0a54d13..055777be79e38a92eb07e93dca8843acab7e608a 100644 (file)
@@ -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 `
index 029fec8840abc8cc8b7ad176241fe666366297a4..17fdfed113e84838de6095716f6d9f8325be8691 100644 (file)
@@ -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);