MCPcopy Create free account
hub / github.com/github/gh-aw / neutralizeBotTriggers

Function neutralizeBotTriggers

actions/setup/js/sanitize_content_core.cjs:790–806  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

788 * @returns {string} The string with excess bot triggers neutralized
789 */
790function 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

Callers 2

sanitizeContentFunction · 0.85
sanitizeContentCoreFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected