fix: correctly capture uri scheme on windows (#16027)

closes https://github.com/neovim/neovim/issues/15261

* normalize uri path to forward slashes on windows
* use a capture group on windows that avoids mistaking drive letters as uri scheme
This commit is contained in:
Michael Lingelbach
2021-10-15 12:03:41 -07:00
committed by GitHub
parent 5fd4557573
commit 68b2a9e569
2 changed files with 27 additions and 1 deletions

View File

@@ -75,13 +75,22 @@ local function uri_from_fname(path)
end
local URI_SCHEME_PATTERN = '^([a-zA-Z]+[a-zA-Z0-9+-.]*):.*'
local WINDOWS_URI_SCHEME_PATTERN = '^([a-zA-Z]+[a-zA-Z0-9+-.]*):[a-zA-Z]:.*'
--- Get a URI from a bufnr
---@param bufnr (number): Buffer number
---@return URI
local function uri_from_bufnr(bufnr)
local fname = vim.api.nvim_buf_get_name(bufnr)
local scheme = fname:match(URI_SCHEME_PATTERN)
local volume_path = fname:match("^([a-zA-Z]:).*")
local is_windows = volume_path ~= nil
local scheme
if is_windows then
fname = fname:gsub("\\", "/")
scheme = fname:match(WINDOWS_URI_SCHEME_PATTERN)
else
scheme = fname:match(URI_SCHEME_PATTERN)
end
if scheme then
return fname
else