Skip to content

fix(terminal-links): detect non-Latin file paths - #13399

Closed
kwangrok92 wants to merge 1 commit into
stablyai:mainfrom
kwangrok92:fix/cjk-terminal-file-links
Closed

kwangrok92 wants to merge 1 commit into
stablyai:mainfrom
kwangrok92:fix/cjk-terminal-file-links

Conversation

@kwangrok92

Copy link
Copy Markdown

Summary

Fixes #13396.
Related to #13397 (found while reducing this one; not addressed here).

Terminal file links were truncated at the first non-Latin character, so Cmd/Ctrl+clicking a Korean, Japanese, Chinese, Cyrillic, or Greek path did nothing.

LOCAL_PATH_REGEX used an ASCII-only character class. For /Users/me/docs/한글폴더/파일.md the match stopped at /Users/me/docs/, leaving the filename outside every link range — hovering it showed no underline and the click was a no-op.

Paths containing a space happened to work, because SPACED_LOCAL_PATH_REGEXES uses a negated class that already accepted those characters. But those regexes only fire when the candidate contains whitespace, so a space was accidentally rescuing non-Latin paths:

Path Before After
/Users/me/docs/folder/file.md linkified linkified
/Users/me/docs/한글폴더/파일.md cut at docs/ linkified
/Users/me/docs/한글 폴더/파일.md linkified linkified

The fix allows \p{L}\p{M}\p{N} in both the relative-prefix and body classes and adds the u flag. \p{M} also keeps macOS NFD (decomposed) names whole, which matters because terminal output is composed while many macOS directory names on disk are not.

Screenshots

No visual change to any UI surface. The only visible difference is that non-Latin paths in the terminal now underline on hover across their full length instead of stopping partway.

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm test
  • pnpm build
  • Added or updated high-quality tests that would catch regressions, or explained why tests were not needed

Added to terminal-links.test.ts:

  • unspaced Korean / Japanese / Chinese / Cyrillic / Greek paths match end to end
  • a relative path starting with a non-Latin segment (한글폴더/파일.md)
  • :line:col suffixes still parse on a non-Latin path
  • an NFD-decomposed path matches whole

Added to terminal-links-redos.test.ts: two non-Latin padding cases, so the widened class stays under the existing linear-time guard.

Note on the full suite: 9 tests fail on my machine, all in src/main/updater.test.ts (linux root package install recovery), src/main/local-downloaded-folder-promotion.test.ts, src/main/startup/run-electron-vite-dev.test.ts, and tests/e2e/cross-version-wire/. I confirmed these are pre-existing by stashing my change and re-running the same files on a clean tree, where they fail identically. None of them touch terminal link parsing. Some also passed when run in isolation but failed under full-suite parallelism, so they look partly flaky and partly environment-dependent (Linux-specific paths running on macOS).

AI Review Report

Reviewed with Claude Code. Focus areas and outcomes:

Cross-platform. The change is a character-class widening, with no platform branching. Verified that the Windows drive-letter alternative ([A-Za-z]:[\\/]) is untouched, and that C:\Users\me\file.txt and backslash separators still match, since \\ remains in the body class. \p{N} preserves the digits the old class allowed, so drive-relative and numeric segments are unaffected. Existing Windows-path tests (isPathInsideWorktree, toWorktreeRelativePath, UNC forward-slash cases) pass unchanged.

Regression surface. Confirmed the previously-supported shapes still match: framework route segments (app/(shop)/products/[productId]/page.tsx:42:7), ~/-prefixed POSIX paths, ./bin, src/foo.ts:12:3, and spaced paths handled by the separate spaced regexes. The u flag required no escaping changes to the existing literal.

Performance. This was the main risk, given the #5970 ReDoS guard. The widened classes still exclude : and all whitespace, so they cannot overlap the (?::\d+)? suffixes or the space padding that caused the original backtracking. The scan stays a single linear character-class repetition. I added non-Latin padding cases to the ReDoS test rather than relying on the ASCII ones.

SSH / remote. No change. Detection runs on terminal text before any local/remote routing decision, and openHttpLink / openDetectedFilePath ownership checks are untouched.

Scope flagged but not changed. BARE_FILENAME_PATTERN in detectBareFilenameLinks is also ASCII-only, so a bare 파일.md token with no separator still is not linkified. I left it alone deliberately: that path resolves tokens against the cwd and is intentionally conservative, and widening it would raise false positives in non-Latin prose. Happy to do it separately if you want it.

Security Audit

Path handling. This widens what text is recognized as a path candidate, not what the app is allowed to open. Every downstream gate is unchanged: parseExplicitFileLinkTarget still rejects trailing separators and non-positive line/column values, openDetectedFilePath still routes through authorizeExternalPath and statRuntimePath, and resolveAuthorizedPath in src/main/ipc/filesystem-auth.ts still enforces the allowed-roots boundary. A path that was previously unlinkable is now clickable, but opening it goes through exactly the same authorization as any ASCII path.

Traversal. \p{L}\p{M}\p{N} adds no separator, ., :, or whitespace characters, so it introduces no new way to express .. or to smuggle a drive/UNC prefix. isDescendantOrEqual remains the containment check.

Command execution / IPC / secrets / dependencies. None touched. No new IPC channel, no shell invocation, no dependency change.

Follow-up. While reducing this I found a separate macOS bug where NFD-normalized directories are detected but never open — filed as #13397. It is not addressed here.

Notes

  • macOS-motivated but not macOS-specific; the bug affected every platform with non-Latin path names.
  • No migration or setting involved.

LOCAL_PATH_REGEX used an ASCII-only character class, so a path match
stopped at the first non-Latin character. `/Users/me/docs/한글폴더/파일.md`
linkified only `/Users/me/docs/`, leaving the filename outside every link
range — hovering showed no underline and Cmd+click did nothing. This hit
every non-Latin script.

Paths containing a space happened to work, because SPACED_LOCAL_PATH_REGEXES
uses a negated class that already accepted those characters, but those
regexes only fire when the candidate contains whitespace.

Allow \p{L}\p{M}\p{N} in both the relative-prefix and body classes and add
the `u` flag. \p{M} keeps macOS NFD names whole. The classes still exclude
`:` and whitespace, so the `:line:col` suffix and the ReDoS guard's linear
scan are unaffected.

Fixes stablyai#13396
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Updated LOCAL_PATH_REGEX to match Unicode letters, combining marks, and digits in terminal paths. Added extraction tests for non-Latin, relative, decomposed Unicode, and line:column paths. Added ReDoS regression cases for large whitespace-padded URLs and Unicode path content.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: detecting non-Latin terminal file paths.
Description check ✅ Passed The description includes all required sections and documents the change, testing, known failures, review, security audit, and platform considerations.
Linked Issues check ✅ Passed The implementation fixes complete detection of non-Latin terminal paths and preserves suffix parsing, punctuation support, and existing path behavior required by issue #13396.
Out of Scope Changes check ✅ Passed The regex update and regression tests are directly related to non-Latin terminal file-link detection, with no unrelated code or dependency changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 0355f881-05ac-4949-991f-be03dc72e099

📥 Commits

Reviewing files that changed from the base of the PR and between 1d3decd and e3a4d3f.

📒 Files selected for processing (3)
  • src/renderer/src/lib/terminal-links-redos.test.ts
  • src/renderer/src/lib/terminal-links.test.ts
  • src/renderer/src/lib/terminal-links.ts

Comment on lines +250 to +255
// macOS stores many names decomposed, while terminal output is composed.
it('detects NFD-decomposed non-Latin paths', () => {
const path = `/Users/me/docs/${'한글폴더'.normalize('NFD')}/${'파일.md'.normalize('NFD')}`
const links = extractTerminalFileLinks(path)
expect(links).toHaveLength(1)
expect(links[0]).toMatchObject({ pathText: path })

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Test an NFD filename with a combining mark.

'한글'.normalize('NFD') produces Hangul Jamo letters. It does not exercise \p{M}. A future removal of \p{M} would pass this test but break names such as café in NFD form. Use an NFD fixture that contains a combining mark.

Proposed test update
-      const path = `/Users/me/docs/${'한글폴더'.normalize('NFD')}/${'파일.md'.normalize('NFD')}`
+      const path = `/Users/me/docs/${'café'.normalize('NFD')}/file.md`
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// macOS stores many names decomposed, while terminal output is composed.
it('detects NFD-decomposed non-Latin paths', () => {
const path = `/Users/me/docs/${'한글폴더'.normalize('NFD')}/${'파일.md'.normalize('NFD')}`
const links = extractTerminalFileLinks(path)
expect(links).toHaveLength(1)
expect(links[0]).toMatchObject({ pathText: path })
// macOS stores many names decomposed, while terminal output is composed.
it('detects NFD-decomposed non-Latin paths', () => {
const path = `/Users/me/docs/${'café'.normalize('NFD')}/file.md`
const links = extractTerminalFileLinks(path)
expect(links).toHaveLength(1)
expect(links[0]).toMatchObject({ pathText: path })

@kwangrok92 kwangrok92 closed this Aug 10, 2026
lazybuttrying pushed a commit to lazybuttrying/orca that referenced this pull request Aug 31, 2026
The stablyai#10573 review showed a trailing trim only fires when the tail is
exactly what it strips. The letters-only form had the same hole: a
particle followed by punctuation or ASCII left the whole span linked.

  plans/foo.mdを(参照)    ->  plans/foo.mdを(参照
  plans/foo.mdへabc       ->  plans/foo.mdへabc
  docs/日本語.md」を 参照  ->  docs/日本語.md」を 参照

The first two were regressions against main, where the ASCII-only class
truncated at the first non-Latin byte by accident. Widening to \p{L}
removes that accident, so the trim has to carry the boundary itself.

Once an ASCII extension closes the name a real path only continues with
ASCII (`/`, `\`, `:line`), so cut at the first \P{ASCII}. Same lookahead
in all three copies of the spaced-path scan: renderer, mobile tap, and
the injected webview mirror that carries its own regexes.

Also pin \p{M} in the NFD test: the fixture decomposes to a combining
mark, so dropping \p{M} now fails (flagged by coderabbit on stablyai#13399).

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01QDkPfyEHWNUW1JQZRe6tKb
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.

[Bug]: Terminal file links are truncated at the first non-Latin character, so CJK paths never open

1 participant