fix(native-chat): reject reference-number false positives

This commit is contained in:
Merge Sim
2026-09-04 18:02:33 -07:00
parent 473418a17e
commit 2b85dcd837
2 changed files with 59 additions and 0 deletions
@@ -386,6 +386,58 @@ describe('CommentMarkdown link click handler', () => {
})
})
it('requires path shape before a spaced line suffix can make a link', () => {
container = document.createElement('div')
document.body.appendChild(container)
root = createRoot(container)
act(() => {
root?.render(
<CommentMarkdown
variant="document"
content='Keep `aspect 16:9` and "John 3:16" as references.'
onLinkClick={vi.fn()}
linkifyFilePaths
/>
)
})
expect(container.querySelectorAll('a')).toHaveLength(0)
expect(container.querySelector('code')?.textContent).toBe('aspect 16:9')
expect(container.textContent).toContain('"John 3:16"')
})
it('preserves line suffixes on valid spaced path shapes', () => {
const content =
'Open "My Folder/notes:12", `My Notes.md:7`, and "C:\\My Folder\\notes.txt:12:3".'
container = document.createElement('div')
document.body.appendChild(container)
root = createRoot(container)
act(() => {
root?.render(
<CommentMarkdown
variant="document"
content={content}
onLinkClick={vi.fn()}
linkifyFilePaths
/>
)
})
const anchors = Array.from(container.querySelectorAll<HTMLAnchorElement>('a'))
expect(anchors.map((anchor) => anchor.textContent)).toEqual([
'My Folder/notes:12',
'My Notes.md:7',
String.raw`C:\My Folder\notes.txt:12:3`
])
expect(anchors.map((anchor) => routeNativeChatHref(anchor.getAttribute('href')))).toEqual([
{ kind: 'file', pathText: 'My Folder/notes:12', line: null },
{ kind: 'file', pathText: 'My Notes.md:7', line: null },
{ kind: 'file', pathText: String.raw`C:\My Folder\notes.txt:12:3`, line: null }
])
})
it('links complete Unicode paths and extensions that begin with a digit', () => {
container = document.createElement('div')
document.body.appendChild(container)
@@ -164,6 +164,13 @@ function exactFileLink(value: string, allowSpacedRelative: boolean): ParsedTermi
if (!parsed) {
return null
}
const hasPathShape =
ROOTED_PATH_PREFIX_PATTERN.test(parsed.pathText) ||
/[\\/]/.test(parsed.pathText) ||
/\.[\p{L}][\p{L}\p{N}\p{M}_+-]*$/u.test(parsed.pathText)
if (!hasPathShape) {
return null
}
const explicitLink = {
...parsed,
startIndex: 0,