Fix media mentions with punctuated filenames#187
Conversation
There was a problem hiding this comment.
Code Review
This pull request improves the mention cleanup logic in ChatBox.tsx by replacing a restrictive regex with a new helper function, hasMentionToken, which supports media names containing punctuation (e.g., "clip-01.mp4"). It also includes minor formatting cleanups. The review feedback points out a potential issue where hasMentionToken could trigger false positives (such as matching email addresses) because it does not verify the character preceding the @ symbol, and provides a code suggestion to resolve this.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| function hasMentionToken(value: string, itemName: string): boolean { | ||
| const normalizedValue = value.toLowerCase(); | ||
| const mention = `@${itemName.toLowerCase()}`; | ||
| let index = normalizedValue.indexOf(mention); | ||
|
|
||
| while (index !== -1) { | ||
| const nextChar = normalizedValue[index + mention.length]; | ||
| if (nextChar === undefined || MENTION_TERMINATOR_PATTERN.test(nextChar)) { | ||
| return true; | ||
| } | ||
| index = normalizedValue.indexOf(mention, index + mention.length); | ||
| } | ||
|
|
||
| return false; | ||
| } |
There was a problem hiding this comment.
The hasMentionToken function currently matches any occurrence of @itemName regardless of what character precedes the @ symbol. This can lead to false positives, such as matching email addresses (e.g., user@domain.mp4 matching an asset named domain.mp4) or other random text containing @.
To prevent this, we should ensure that the character immediately preceding the @ symbol is either a whitespace character or that the @ is at the start of the string. This is also consistent with the mention trigger logic on line 419.
function hasMentionToken(value: string, itemName: string): boolean {
const normalizedValue = value.toLowerCase();
const mention = `@${itemName.toLowerCase()}`;
let index = normalizedValue.indexOf(mention);
while (index !== -1) {
const prevChar = index > 0 ? normalizedValue[index - 1] : undefined;
if (prevChar === undefined || /\s/.test(prevChar)) {
const nextChar = normalizedValue[index + mention.length];
if (nextChar === undefined || MENTION_TERMINATOR_PATTERN.test(nextChar)) {
return true;
}
}
index = normalizedValue.indexOf(mention, index + mention.length);
}
return false;
}
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | -381 |
| Duplication | 0 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
Summary
Fix media mentions in the chat box so selected video files keep being sent to the AI assistant when their filenames include punctuation or spaces.
Changes
\w-based mention cleanup check with exact media-name matching.clip-01.mp4andmy video.movremain valid mentions without matching longer partial names.Testing
pnpm exec eslint app/components/chat/ChatBox.tsxpnpm exec prettier --check app/components/chat/ChatBox.tsx.,-, and spaces.Screenshots / Recordings (if UI)
N/A
Related Issues
Closes #29
Breaking Changes
None
Deployment Notes
None