Skip to content

Skip paths starting with /\ in file link detection - #854

Merged
dakra merged 1 commit into
mainfrom
fix/skip-backslash-unc-paths
Dec 1, 2026
Merged

dakra merged 1 commit into
mainfrom
fix/skip-backslash-unc-paths

Conversation

@dakra

@dakra dakra commented Dec 1, 2026

Copy link
Copy Markdown
Owner

Closes #853.

The file pass of link detection skips candidates starting with //, because on Windows they name a network share and file-exists-p blocks for seconds looking up the host. That guard tests the raw match. On Windows a backslash is also a directory separator, and expand-file-name normalises it to a slash, so a candidate such as the regex /\r/g passed the guard, expanded to //r/g, and hit the same lookup.

The guard now skips candidates starting with /\ as well. It stays on the raw match: a relative path in a shell whose cwd is on a share still expands onto the share afterwards and links as before.

Behaviour

Output text Before (Windows) After
s.replace(/\r/g, '') hang on host r skip
x = /\d+/.test(y) hang on host d+ skip
split(/\s*,\s*/) hang skip
sed 's/\r//' (relative s/\r/) local stat local stat
/etc/hosts, src/main.rs:42:4, ./a.el:3, ~/.zshrc link link

With the shipped ghostel-file-detection-path-regex a candidate cannot start with a backslash, so // and /\ are the only shapes that expand to a share. Doubled separators later in a path collapse to one, since expand-file-name preserves // only at the very start of a name.

On Linux and macOS these candidates are skipped too, which saves one stat per regex literal. The only link lost is to a file directly under / whose name starts with a backslash.

Tests

One new test, running on every platform: a line with /\r/g, /\d+/.test and a real fixture file. It asserts no /\ or // path reaches file-exists-p and only the fixture links. It fails with the guard change reverted.

The hang itself was not reproduced on Windows; the Windows behaviour is taken from Fexpand_file_name in the Emacs source.

On Windows a backslash is a directory separator, so `expand-file-name'
turns a candidate such as the regex `/\r/g' into the network share
`//r/g', and `file-exists-p' blocks for seconds looking up the host.
The guard that skips `//' candidates tests the raw match, which let
these through.

Closes #853.
@dakra
dakra merged commit 71f17de into main Dec 1, 2026
30 of 32 checks passed
@dakra
dakra deleted the fix/skip-backslash-unc-paths branch December 1, 2026 09:35

This branch was successfully deployed

1 active deployment
github-pages — 71f17de7 Deployed Dec 1, 2026 by dakra via deploy #301
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.

Skip paths starting with /\ in file link detection

1 participant