Repository navigation
fix(terminal-links): detect non-Latin file paths - #13399
kwangrok92 wants to merge 1 commit into
Conversation
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
📝 WalkthroughWalkthroughUpdated 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (3)
src/renderer/src/lib/terminal-links-redos.test.tssrc/renderer/src/lib/terminal-links.test.tssrc/renderer/src/lib/terminal-links.ts
| // 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 }) |
There was a problem hiding this comment.
🎯 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.
| // 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 }) |
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
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_REGEXused an ASCII-only character class. For/Users/me/docs/한글폴더/파일.mdthe 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_REGEXESuses 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:/Users/me/docs/folder/file.md/Users/me/docs/한글폴더/파일.mddocs//Users/me/docs/한글 폴더/파일.mdThe fix allows
\p{L}\p{M}\p{N}in both the relative-prefix and body classes and adds theuflag.\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 lintpnpm typecheckpnpm testpnpm buildAdded to
terminal-links.test.ts:한글폴더/파일.md):line:colsuffixes still parse on a non-Latin pathAdded 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, andtests/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 thatC:\Users\me\file.txtand 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. Theuflag required no escaping changes to the existing literal.Performance. This was the main risk, given the
#5970ReDoS 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/openDetectedFilePathownership checks are untouched.Scope flagged but not changed.
BARE_FILENAME_PATTERNindetectBareFilenameLinksis also ASCII-only, so a bare파일.mdtoken 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:
parseExplicitFileLinkTargetstill rejects trailing separators and non-positive line/column values,openDetectedFilePathstill routes throughauthorizeExternalPathandstatRuntimePath, andresolveAuthorizedPathinsrc/main/ipc/filesystem-auth.tsstill 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.isDescendantOrEqualremains 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