Skip to content
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

bufadd does not sanitize windows drive letter capitalization #16331

Open
mjlbach opened this issue Nov 16, 2021 · 6 comments
Open

bufadd does not sanitize windows drive letter capitalization #16331

mjlbach opened this issue Nov 16, 2021 · 6 comments
Labels
bug issues reporting wrong behavior platform:windows

Comments

@mjlbach
Copy link
Contributor

mjlbach commented Nov 16, 2021

Neovim version (nvim -v)

NVIM v0.6.0-dev+463-g68b2a9e56

Vim (not Nvim) behaves the same?

N/A (pretty sure the pathing code diverged a long time ago)

Operating system/version

Widnows 10

Terminal name/version

Windows Termianal

$TERM environment variable

N/A

Installation

source build

How to reproduce the issue

file_location = os.getenv('TEMP')

local file_1 = file_location .. "\\file_1.txt"
local buffer_1 = vim.fn.bufadd(file_1)
print(vim.api.nvim_buf_get_name(buffer_1))

local drive_letter = string.sub(file_location, 1, 1)
local tail = string.sub(file_location, 2)
local perturbed_path = string.lower(drive_letter) .. tail
local file_2 = perturbed_path .. "\\file_2.txt"

local buffer_2 = vim.fn.bufadd(file_2)
print(vim.api.nvim_buf_get_name(buffer_2))

Expected behavior

vim.api.nvim_buf_get_name should show consistent capitalization for drive letters on windows regardless of the input to buf_add (which based on the code seems like it depends more on bufadd behavior than buf_get_name)

Actual behavior

C:\Users\michael\AppData\Local\Temp\file_1.txt
c:\Users\michael\AppData\Local\Temp\file_2.txt
@zeertzjq
Copy link
Member

Does this bug also apply to Vim and Nvim's bufname()?

@mjlbach
Copy link
Contributor Author

mjlbach commented Nov 16, 2021

yes, the behavior depends on bufadd, not buf_get_name/bufname

@erw7
Copy link
Contributor

erw7 commented Nov 17, 2021

I don't think this is a neovim (or vim) bug. If 'fileignorecase' is set properly, path_fnamecmp() will handle those differences properly. I think that is why bufadd does not do capitalization.

@zeertzjq zeertzjq added enhancement feature request and removed bug issues reporting wrong behavior bug-vim wrong behavior inherited from vim labels Nov 17, 2021
@mjlbach
Copy link
Contributor Author

mjlbach commented Nov 19, 2021

I guess the question is should it then. Currently when we want to compare on the lua side we have to sanitize the drive letter capitalization (which, to be fair, is trivial to do), because buf_get_name returns different values depending on the call to buff_add. I'm just not sure this behavior is intuitive

see:

@hasansujon786
Copy link

I am having the same issue. Different results for different files.
-- c:\Users\hasan\dotfiles\nvim\lua\options.lua -- C:\Users\hasan\dotfiles\nvim\init.lua

@3N4N
Copy link
Contributor

3N4N commented Mar 22, 2023

Was there any headway into fixing this? Does it even need fixing? As I see it, this shouldn't cause any problem. Sure, bufadd() doesn't capitalize drive letter, where is the problem in that? It's not like when you call buffadd() again with the same filename, but this time with different case of drive letter, it opens a new buffer. No, bufadd() behaves sensibly. It doesn't add a new buffer, even if the second call to buffadd() had a different case of drive letter.

Funny aside: command prompt doesn't sanitize drive letters either. If you do cd /d c:\, the prompt shows lowercase "c." If you do cd /d C:\, the prompt shows uppercase "C." No one cares.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug issues reporting wrong behavior platform:windows
Projects
None yet
Development

No branches or pull requests

5 participants