Skip to content

fix(messages): fixed crash when clicking on a file url#515

Open
Samigos wants to merge 3 commits intoDimillian:mainfrom
Samigos:investigate/file-link-crash
Open

fix(messages): fixed crash when clicking on a file url#515
Samigos wants to merge 3 commits intoDimillian:mainfrom
Samigos:investigate/file-link-crash

Conversation

@Samigos
Copy link
Contributor

@Samigos Samigos commented Feb 25, 2026

Issue

There is a crash when clicking on a file url in a message.

Summary

  • route only likely filesystem markdown hrefs through the file opener
  • keep non-file relative markdown links as normal anchors (e.g. /help/getting-started)
  • prevent malformed codex-file: links from navigating/crashing by safely swallowing click
  • add regression tests for href file links, non-file relative links, and malformed codex-file links

Validation

  • npm run test -- src/features/messages/components/Messages.test.tsx
  • npm run typecheck
  • npm run test

@Samigos Samigos changed the title fix(messages): harden file link routing in markdown fix(messages): fixed crash when clicking on a file url Feb 25, 2026
@Samigos
Copy link
Contributor Author

Samigos commented Feb 25, 2026

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fe1e95818c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 608 to 612
if (isLikelyFileHref(url)) {
const directPath = getLinkablePath(url);
if (directPath) {
return directPath;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Decode percent-encoded hrefs before opening file links

resolveHrefFilePath returns the raw href path as soon as it looks file-like, so links such as ./docs/My%20Guide.md are passed to onOpenFileLink with %20 still encoded. useFileLinkOpener then forwards that raw string to open_workspace_in, which means real files containing spaces (or other encoded characters) fail to open even though the link is valid markdown.

Useful? React with 👍 / 👎.

Comment on lines 271 to 275
if (
trimmed.startsWith("~/") ||
trimmed.startsWith("./") ||
trimmed.startsWith("../")
) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid treating all dot-relative links as filesystem paths

This classifies every ./... and ../... markdown link as a file link, so non-file relative links (for example documentation routes like ./help/getting-started) are intercepted by handleFileLinkClick instead of behaving as normal anchors. That regresses existing markdown navigation behavior for relative links that are not local files.

Useful? React with 👍 / 👎.

@Samigos
Copy link
Contributor Author

Samigos commented Feb 25, 2026

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e3f23ed161

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 262 to 264
if (trimmed.startsWith("/")) {
return hasLikelyLocalAbsolutePrefix(trimmed);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Treat non-whitelisted absolute paths as file hrefs

The new absolute-path branch only returns true for a small prefix allowlist, so links like /workspace/.../file.tsx:12 or /usr/... are not routed through onOpenFileLink even though they are valid file paths and getLinkablePath can parse them. In those environments the link still falls back to a normal anchor navigation, which means the crash path this change is fixing remains reproducible for common Linux/container paths.

Useful? React with 👍 / 👎.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e3f23ed161

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 677 to 680
<a
href={href ?? toFileLink(hrefFilePath)}
onClick={(event) => handleFileLinkClick(event, hrefFilePath)}
onContextMenu={(event) => handleFileLinkContextMenu(event, hrefFilePath)}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve anchor navigation when no file opener is wired

The new hrefFilePath branch always binds onClick to handleFileLinkClick, which unconditionally calls event.preventDefault() before invoking optional onOpenFileLink. For Markdown call sites that do not pass onOpenFileLink (for example the PR summary/comment renderer in src/features/git/components/GitDiffViewerPullRequestSummary.tsx), file-like relative links such as docs/setup.md now become inert instead of behaving as normal anchors. This is a regression introduced by the new href-file routing path and should fall back to plain anchor behavior when no file opener is available.

Useful? React with 👍 / 👎.

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.

1 participant