mirror of
https://github.com/neovim/neovim.git
synced 2026-06-16 00:31:16 +00:00
fix(gf): handle local file: URI paths #38915
Problem:
`gf` and `<cfile>` treat `file:/absolute/path` as a literal path and
open `file:/...` instead of the local file.
Solution:
Strip the local `file:` prefix before path resolution in the hyperlink
path code.
(cherry picked from commit e827c3b648)
This commit is contained in:
committed by
github-actions[bot]
parent
465aa2af1d
commit
d86d9759e5
@@ -1759,6 +1759,13 @@ char *find_file_name_in_path(char *ptr, size_t len, int options, long count, cha
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((options & FNAME_HYP) && len > 6 && strncmp(ptr, "file:/",
|
||||
6) == 0 && !vim_ispathsep(ptr[6])) {
|
||||
size_t off = path_has_drive_letter(ptr + 6, len - 6) ? 6 : 5;
|
||||
ptr += off;
|
||||
len -= off;
|
||||
}
|
||||
|
||||
if ((options & FNAME_INCL) && *curbuf->b_p_inex != NUL) {
|
||||
tofree = eval_includeexpr(ptr, len);
|
||||
if (tofree != NULL) {
|
||||
|
||||
@@ -160,6 +160,17 @@ describe('file search', function()
|
||||
)
|
||||
end)
|
||||
|
||||
it('gf/<cfile> handles local file: paths', function()
|
||||
local path = fn.fnamemodify(join_path(testdir, 'gf-target.txt'), ':p'):gsub('\\', '/')
|
||||
local uri = 'file:' .. (is_os('win') and '/' or '') .. path
|
||||
write_file(path, '')
|
||||
insert(uri)
|
||||
command('norm! 0')
|
||||
eq(path, eval('expand("<cfile>")'))
|
||||
feed('gf')
|
||||
eq(path, fn.fnamemodify(eval('expand("%:p")'), ':p'):gsub('\\', '/'))
|
||||
end)
|
||||
|
||||
---@param funcname 'finddir' | 'findfile'
|
||||
local function test_find_func(funcname, folder, item)
|
||||
local d = join_path(testdir, folder)
|
||||
|
||||
Reference in New Issue
Block a user