From 925765f099dcdc3b12316eaa6dc3c17506734b51 Mon Sep 17 00:00:00 2001 From: Doug Richar Date: Thu, 17 Oct 2024 21:08:36 -0400 Subject: [PATCH] fix: improve @mention parsing for GitHub usernames (#33) - Update regex to correctly identify valid GitHub usernames - Prevent false positives for package names and email addresses - Exclude matches within code snippets, URLs, and Markdown links --- index.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 100654d..09c9f4b 100644 --- a/index.js +++ b/index.js @@ -28,11 +28,14 @@ const reduceNewlines = (text) => text.replace(/\n\s*\n/g, (ws) => { }); /** - * Converts @mentions to GitHub profile links. + * Converts @mentions to GitHub profile links for valid GitHub usernames. * @param {string} text The input text. - * @returns {string} The text with @mentions converted to links. + * @returns {string} The text with valid @mentions converted to links. */ -const convertMentionsToLinks = (text) => text.replace(/@(\S+)/g, (match, name) => `[@${name}](https://github.com/${name})`); +const convertMentionsToLinks = (text) => text.replace( + /(? `[@${name}](https://github.com/${name})` +); /** * Reduces headings to a smaller format if 'reduce_headings' is enabled.