* Neutralizes bot trigger phrases by wrapping them in backticks. * The first `maxBotMentions` unquoted trigger references are left unchanged; * any occurrences beyond that threshold are wrapped in backticks. * Already-quoted entries are never re-quoted. * @param {string} s - The string to proces
(s, maxBotMentions = MAX_BOT_TRIGGER_REFERENCES)
| 788 | * @returns {string} The string with excess bot triggers neutralized |
| 789 | */ |
| 790 | function neutralizeBotTriggers(s, maxBotMentions = MAX_BOT_TRIGGER_REFERENCES) { |
| 791 | // Match unquoted bot trigger phrases like "fixes #123", "closes #asdfs", etc. |
| 792 | // The negative lookbehind (?<!`) skips already-quoted entries. |
| 793 | const pattern = /(?<!`)\b(fixes?|closes?|resolves?|fix|close|resolve)\s+#(\w+)/gi; |
| 794 | const matches = s.match(pattern); |
| 795 | if (!matches || matches.length <= maxBotMentions) { |
| 796 | return s; |
| 797 | } |
| 798 | let count = 0; |
| 799 | return s.replace(pattern, (match, action, ref) => { |
| 800 | count++; |
| 801 | if (count <= maxBotMentions) { |
| 802 | return match; |
| 803 | } |
| 804 | return `\`${action} #${ref}\``; |
| 805 | }); |
| 806 | } |
| 807 | |
| 808 | /** |
| 809 | * Neutralizes template syntax delimiters to prevent potential template injection |
no outgoing calls
no test coverage detected