Skip to content

BUG: Cannot open files with spaces in the path on Windows #1076

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
3 tasks done
wizcas opened this issue Jul 30, 2023 · 1 comment · Fixed by #1077
Closed
3 tasks done

BUG: Cannot open files with spaces in the path on Windows #1076

wizcas opened this issue Jul 30, 2023 · 1 comment · Fixed by #1077
Labels
bug Something isn't working

Comments

@wizcas
Copy link
Contributor

wizcas commented Jul 30, 2023

Did you check docs and existing issues?

  • I have read all the docs.
  • I have searched the existing issues.
  • I have searched the existing discussions.

Neovim Version (nvim -v)

0.9.1

Operating System / Version

Windows11 22H2 22621.2070

Describe the Bug

On Windows, when trying to open a file in neo-tree with any spaces in the file's path, it shows an empty buffer.

It seems that neo-tree tries to replace all \s into /s which wouldn't suit all the cases on Windows. I came to this conclusion because If I try to save the faulty "empty" buffer, neovim will say the file cannot be found; the expected path, d:\test\ path\test.txt for example, is converted to d:/test/ path/test.txt by neo-tree, where the escaped space \ becomes / which is invalid.

This problem doesn't exist by opening the file via its path directly or by nvim-tree

Screenshots, Traceback

I tried this in a clean neovim environment with only Lazy and neo-tree installed.

image

Steps to Reproduce

  1. Create or find a directory with one or more spaces in its path
  2. Open a file within the directory
  3. [Phenomenon 1] The opened buffer won't show the file's content
  4. Save the opened buffer
  5. [Phenomenon 2] It'll show an error message of 'no such file or directory'.

Expected Behavior

File should be opened and saved

Your Configuration

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath, })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  "folke/tokyonight.nvim",
  -- add any other plugins here
}

local neotree_config = {
  "nvim-neo-tree/neo-tree.nvim",
  dependencies = { "MunifTanjim/nui.nvim", "nvim-tree/nvim-web-devicons", "nvim-lua/plenary.nvim" },
  cmd = { "Neotree" },
  keys = {
    { "<Leader>e", "<Cmd>Neotree<CR>" }, -- change or remove this line if relevant.
  },
  opts = {},
}

table.insert(plugins, neotree_config)
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here
@wizcas wizcas added the bug Something isn't working label Jul 30, 2023
@wizcas
Copy link
Contributor Author

wizcas commented Jul 30, 2023

I tried to debug. It turns out it's the utils.escape_path which caused this problem. The problematic part is introduced by PR #1023

I added some logs

M.escape_path = function(path)
  local escaped_path = vim.fn.fnameescape(path)
  log.info("escaped 0: " .. escaped_path)
  if M.is_windows then
    log.info("is windows")
    escaped_path = escaped_path:gsub("\\", "/")
    log.info("escaped 1: " .. escaped_path)
  end
  return escaped_path
end

And the output is:

[Neo-tree INFO] opening path: d:\test path\test.txt, open_file: nil
[Neo-tree INFO] escaped 0: d:\test\ path\test.txt
[Neo-tree INFO] is windows
[Neo-tree INFO] escaped 1: d:/test/ path/test.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant