echasnovski / mini.nvim

Library of 40+ independent Lua modules improving overall Neovim (version 0.8 and higher) experience with minimal effort
MIT License
4.54k stars 175 forks source link

mini.files: '\' is treated as current directory #875

Closed wroyca closed 2 months ago

wroyca commented 2 months ago

Contributing guidelines

Module(s)

files

Description

In mini.files, \ represents the current directory. Accidentally deleting it can result in losing the entire current directory. On several occasions, \ has mistakenly found its way into my project directories during quick operations, leading me to inadvertently attempt its deletion without paying attention, only to end up deleting everything.

For the most part, attempting to create \ from mini.files will not work, but some operation with mini.files will let it slip by from time to time, though I don't know which, as it happen very sporadically. Still, the proper behavior here would be to allow \ and treat it as a proper directory/file like everything else.

Neovim version

NVIM v0.10.0-dev+3111-g6ec6fafd6

Steps to reproduce

  1. nvim -nu scripts/minimal_init.lua
  2. !mkdir \
  3. lua require("mini.files").open()
  4. Try to delete \
  5. Sync

Expected behavior

\ is recognized as valid filename and/or directory.

Actual behavior

\ is incorrectly recognized as the current directory.

image image

echasnovski commented 2 months ago

Thanks for the issue!

Yes, I can reproduce this in various ways. I'll take a look.

echasnovski commented 2 months ago

This should now work on main branch.

As suspected, it was due to path normalization which replaced all "\" with "/" on all platforms (because using "\" in paths even on Unix is bad). I opted for a more precise normalization depending on platform.

Thanks again for noticing this!