Skip to content

Fix Windows path handling + tests#136

Open
SingingTree wants to merge 3 commits intoMLFlexer:mainfrom
SingingTree:upstreaming-windows-path-fixes
Open

Fix Windows path handling + tests#136
SingingTree wants to merge 3 commits intoMLFlexer:mainfrom
SingingTree:upstreaming-windows-path-fixes

Conversation

@SingingTree
Copy link

This PR fixes various windows path handling bugs. Building on #134 it

  • Removes the /p flag which breaks mkdir on Windows.
  • Handles sanitizing reserved characters in path names on windows (: [ ] ? /).
  • Fixes some path construction bugs that meant get_file_path wasn't using type so state_dir/workspace/name.json would be incorrectly rendered as state_dir/name.json.

It also

  • Adds tests.
  • Adds handling to different windows path forms (e.g., relative paths like C:foo).
  • Adds more robust quoting of paths.
  • Handles restoring paths from inside WSL for /mnt/<drive letter> paths.

Individual commits are self-describing — see the commit log for details.

…truction

Covers the path handling behaviour added and fixed in the sibling commit:

ensure_folder_exists: nested creation, idempotency, spaces in directory
names, relative paths, the negative case where a file blocks a path
segment, and Windows-specific forms (absolute drive letter, drive-relative
C:foo normalisation). UNC paths are explicitly noted as untestable without
a live network share or privileged loopback.

state_manager get_file_path (exercised via load_state, which passes its
return value straight to file_io.load_json): separator between
save_state_dir and type, path separator sanitisation in file names, and
reserved character sanitisation (: [ ] ? /).

Also adds a Testing section to README.md documenting how to install Busted
via LuaRocks and run the suite, including Windows-specific notes about
using PowerShell and providing a GCC toolchain for native dependencies.
utils.lua — ensure_folder_exists:
- Removes the invalid /p flag on Windows mkdir and -p on Unix; the
  segment-by-segment loop makes both unnecessary.
- Fixes a gsub bug where the closing quote was inside the replacement
  string, corrupting any path containing a forward slash on Windows.
- Adds shell_mkdir with proper quoting: single-quote wrapping on Unix
  (neutralises spaces and most metacharacters), double-quote on Windows
  with rejection of " (not a valid NTFS filename character).
- Adds parse_root to handle all Windows path forms: absolute (C:\foo),
  drive-relative (C:foo normalised to C:\foo), and UNC (\server\share,
  supported only when the share already exists).
- Adds mkdir_if_missing to encapsulate the existence-check-then-create
  pattern, leaving ensure_folder_exists as a clean orchestrator.

state_manager.lua — get_file_path:
- Fixes a missing separator between save_state_dir and type in the format
  string, which produced paths like state_dir/name.json instead of
  state_dir/workspace/name.json.
- Expands filename sanitisation to cover Windows reserved characters
  (: [ ] ? /) in addition to the platform path separator.
WezTerm reports WSL pane working directories as /mnt/c/... (the WSL
mount path). The Windows mux rejects these when spawning restored panes
because they are not valid Windows paths.

Convert /mnt/<drive>/<rest> to <DRIVE>:\<rest> at save time so the
stored CWD is a Windows path the mux can validate. The existing
/C:/... -> C:\... strip is retained for native Windows panes.

Pure Linux paths (/home/...) remain unresolvable in a Windows mux
context and are left as-is.
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