Skip to content

Make full-path syntax mappings work on Windows - #4113

Merged
keith-hall merged 3 commits into
sharkdp:masterfrom
b84330808:fix-map-syntax-glob-colon
Nov 5, 2026
Merged

keith-hall merged 3 commits into
sharkdp:masterfrom
b84330808:fix-map-syntax-glob-colon

Conversation

@b84330808

Copy link
Copy Markdown
Contributor

--help says --map-syntax globs match the full path, but that doesn't work on Windows:

  • --map-syntax "C:/projects/*.conf:INI" fails with "Invalid syntax mapping", because the argument is split on every :. It now splits on the last one.
  • The pattern still wouldn't match, because PathAbs and fs::canonicalize give \?\C:\... on Windows. The built-in ${HOME}/.config/git/config style mappings never matched for the same reason. The path is now also tried without that prefix.

The new tests fail without the change and pass with it on Windows 11. I haven't run them on Linux or macOS.

`--map-syntax` split its argument on every `:`, so `C:/dir/*.conf:INI` was
rejected as an invalid mapping. Split on the last `:` instead.

The pattern still could not match, because `PathAbs` and `fs::canonicalize`
return verbatim paths such as `\\?\C:\dir\file.conf` on Windows. That also kept
the built-in `${HOME}` and `${XDG_CONFIG_HOME}` mappings from ever matching.
Try the path without the verbatim prefix as well.
@b84330808
b84330808 force-pushed the fix-map-syntax-glob-colon branch from 53c5a75 to b843b05 Compare November 5, 2026 12:27

@keith-hall keith-hall left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hey, thanks for creating this PR and raising awareness of the problem - I definitely agree with the goal to improve Windows compatibility. I wonder if stripping those prefixes is the best way to do it though - it means that mappings containing those verbatim paths wouldn't be matched... Is there perhaps some other way we could do it, to support globs etc with and without verbatim path prefixes, for maximum compatibility?

I was also considering asking to gate the colon splitting change to just Windows but realised it wouldn't allow us to include mappings for Windows by default (unless we have different mappings per platform, and shat may not play well with Git Bash for Windows etc) so that part is fine upon reflection - as long as globs/paths valid on one system don't cause problems with others but kinda get ignored I think it should be okay.

@b84330808

b84330808 commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for looking! It does not replace the path, it tries both: get_syntax_for still matches the original path first, then also tries the one without the prefix. I ran these on Windows with and without this PR:

Pattern Path Before After
\\?\C:\dir\*.myconf \\?\C:\dir\file.myconf match match
//?/C:/dir/*.myconf \\?\C:\dir\file.myconf match match
\\?\UNC\server\share\*.myconf \\?\UNC\server\share\file.myconf match match
\\?\C:\dir\*.myconf C:\dir\file.myconf no no
C:/dir/*.myconf \\?\C:\dir\file.myconf no match
C:\dir\*.myconf \\?\C:\dir\file.myconf no match
\\server\share\*.myconf \\?\UNC\server\share\file.myconf no match

So nothing that matched stops matching. The one gap is the fourth row: a pattern with the prefix doesn't match a path without it, same as before. I don't think that comes up for bat <file>, since the path goes through PathAbs and gets the prefix, but I can add it if you'd like. I pushed a test case for a mapping with a literal prefix.

These went through SyntaxMapping::insert directly. On the command line a \\?\C:\... pattern could not get through before, because of the colon split.

And yes, the colon split isn't gated on Windows: rsplit_once gives the same result for any pattern without an extra colon, and a Windows path in a mapping on Linux just never matches.

@keith-hall keith-hall left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good, thanks for the explanation and additional test case

@keith-hall
keith-hall enabled auto-merge November 5, 2026 20:46
@keith-hall
keith-hall merged commit 408801f into sharkdp:master Nov 5, 2026
24 checks passed
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.

2 participants