Skip to content

fix(web): 带行号的网页链接不再当作工作区文件 - #496

Merged
Qiyuanqiii merged 4 commits into
mainfrom
Qiyuanqiii/file-link-scheme-line
Oct 27, 2026
Merged

Qiyuanqiii merged 4 commits into
mainfrom
Qiyuanqiii/file-link-scheme-line

Conversation

@Qiyuanqiii

Copy link
Copy Markdown
Member

parseProjectFileLink 会拒绝未知协议,但保留了一个形如 foo.ts:12 的本地路径例外。这个例外没有限定协议部分,带行号的网页链接也会命中:https://example.com/report.md:12 会被解析成工作区路径 https://example.com/report.md(行 12)。ResourceLink 随后按文件链接渲染——文件图标、#workspace-file href、文件悬浮提示和文件右键菜单;只有点击时因为 webURL 优先才打开网页,交互前后不一致。

修复把行号解析提前到协议判断之前,让 https: 在去掉 :12 后仍能被识别为协议并拒绝;同时移除 \.\w+:\d+ 这个会掩盖协议的例外。src/report.md:12 和 C:/project/report.md:12 仍按文件路径解析,file:/// 的处理不变。

回归用例:

  • https://example.com/report.md:12:旧实现返回 { path: "https://example.com/report.md", line: 12 },新实现返回 null
  • mailto:user@example.com:12:不再被当作文件
  • src/report.md:12 与 C:/project/report.md:12:保持原结果

验证:

  • npx vitest run src/v2/components/resource-link.test.tsx:11/11 通过;新增用例在旧实现下失败
  • 全量 npx vitest run:268 个文件、2608 个用例全部通过
  • npm run typecheck:通过
  • npm run build:通过
  • OCR delegate 复核:1 个可复核文件(共 2 个,测试文件被默认路径规则排除),按规则组自查无发现;排除的测试文件已手工复核

边界:没有在真实浏览器里点击或悬浮该链接;本次只改解析结果,未改 ResourceLink 的展示规则。以 scheme: 开头的顶层字符串(如 a:b.md:12)现在按协议处理并拒绝;带目录部分的 src/a:b.md:12 仍按路径处理。

@Qiyuanqiii
Qiyuanqiii merged commit f596e64 into main Oct 27, 2026
13 checks passed
@Qiyuanqiii
Qiyuanqiii deleted the Qiyuanqiii/file-link-scheme-line branch October 27, 2026 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants