fix: normalize path separators in WSL remote sessions - #229
Open
88871 wants to merge 1 commit into
Open
Conversation
When the extension runs on a non-Windows host (WSL remote, SSH remote) but the configured journal base path is a Windows-style drive path such as C:\Users\...\journal, the path components were concatenated with a mix of backslashes and forward slashes. The result was a malformed path like /C:\Users\...\journal/2026/05/20.md that VS Code could not resolve, causing an empty buffer to be shown instead of the journal entry (pajoma#228). Two-layer fix: 1. conf.ts – normalizeBasePathForRuntime: besides the existing /mnt/<drive>/... conversion for explicit Windows drive paths, now also replaces stray backslashes in non-drive POSIX paths so that any Windows-style separator that slipped in via ${workspaceFolder} or similar variables is cleaned up before the path is returned from getBasePath(). 2. template-service.ts – getResolvedEntryPath / getResolvedNotesPath / getResolvedWeeklyNotesPath / getWeekPathPattern: after all template variables are substituted, replace any remaining backslashes with forward slashes on non-Windows hosts before Path.normalize() runs. This acts as a belt-and-suspenders guard so that a Windows-style base path that somehow passes through getBasePath() unchanged cannot corrupt the final resolved path string.
88871
force-pushed
the
fix/wsl-path-normalization
branch
from
May 20, 2026 02:49
4beac2d to
8f0c18a
Compare
pajoma
requested changes
Jun 1, 2026
pajoma
left a comment
Owner
There was a problem hiding this comment.
Thanks for the contribution and the detailed PR description.
Before this can merge, tests are required. The bug is in a platform-specific code path that is easy to cover with plain Node (no VS Code needed):
normalizeBasePathForRuntime must have unit tests covering at minimum:
C:\Users\foo\journal→/mnt/c/Users/foo/journal/C:\Users\foo\journal(leading slash, as observed in the bug) →/mnt/c/Users/foo/journal/mnt/c/Users/foo/journal(already POSIX) → unchanged- mixed-separator non-drive path (e.g.
foo\bar/baz) → backslashes replaced
Without tests, any future refactor of this function or the surrounding getBasePath logic will have no safety net, and the exact scenario from the issue (mixed slashes, leading slash before drive letter) could regress silently.
Additional concerns noted in review (not blockers on their own, but worth addressing):
- The backslash guards added to
template-service.tsare redundant —getBasePath()already callsnormalizeBasePathForRuntime(), so by the time${base}is substituted, no backslash survives. The fix should live inconf.tsonly. - PR description states "Detection uses both
process.platformandvscode.env.remoteName" — the code only usesprocess.platform. Please correct the description. - The
/mnt/<drive>mapping is WSL-specific. The description claims coverage for "WSL/SSH/containers" but a plain SSH remote to a Linux host would get a nonsensical/mnt/c/...path. Please narrow the claim or gate the/mntmapping onvscode.env.remoteName === 'wsl'.
Happy to iterate once tests are in place.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #228
Problem
When
vscode-journalis active in a WSL Remote VS Code session and theconfigured journal base path is a Windows-style drive path (e.g.
C:\Users\<user>\Git\journal), theJournal: Todaycommand opens an emptyeditor at a malformed path like:
The Windows drive path is concatenated with POSIX-style date components,
then
vscode.Uri.file()prepends a/to make it absolute on Linux, producinga path that does not exist.
Root cause
Path construction in
TemplateServicesubstitutes${base}with the rawvalue from
getBasePath()and then callsPath.normalize()(the POSIXpathmodule on Linux). POSIXpath.normalizedoes not treat\as aseparator, so backslashes from the Windows-style config value survive intact
into the resolved path string.
Fix
Two-layer defence:
conf.ts–normalizeBasePathForRuntime: the existing/mnt/<drive>/...mapping for explicit Windows drive paths is kept. Additionally, on non-Windows
hosts any residual backslashes in non-drive paths (e.g. injected via
${workspaceFolder}) are now replaced with forward slashes before the valueis returned from
getBasePath().template-service.ts– after all template variables are substituted,replace any remaining
\characters with/on non-Windows hosts beforePath.normalize()is called. This coversgetResolvedEntryPath,getResolvedNotesPath,getResolvedWeeklyNotesPath, andgetWeekPathPattern— every code path that produces a filesystem path for the active session.
The
ForLocalOpenvariants are intentionally left unchanged because theyintentionally preserve Windows-style paths for hand-off to the local client.
Result
With the fix, a configured base path of
C:\Users\<user>\Git\journalin aWSL remote session is first mapped to
/mnt/c/Users/<user>/Git/journalbynormalizeBasePathForRuntime, and after date substitution and the backslashguard in the template service the final path is a clean POSIX path such as:
No existing test assertions are changed; the fix is purely additive.