vim-patch:9.1.0359: MS-Windows: relative import in a script sourced from a buffer doesn't work

Problem:  MS-Windows: Relative import in a script sourced from a buffer
          doesn't work (Ernie Rael)
Solution: Set a filename, so that we are not trying to use
          script-relative filename (Yegappan Lakshmanan)

When a script is sourced from a buffer, the file name is set to ":source
buffer=". In MS-Windows, the ":" is a path separator character (used
after a drive letter). This results in the code trying to use the ":"
prefix to import the script on MS-Windows. To fix this, when importing a
script from a script sourced from a buffer with nofile, don't use
a script relative path name.

fixes vim/vim#14588
closes: vim/vim#14603

f135fa28e4

Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
This commit is contained in:
Jan Edmund Lazo
2025-10-20 21:20:08 -04:00
parent 96a514ed46
commit 2a28149efc
2 changed files with 18 additions and 10 deletions

View File

@@ -247,12 +247,15 @@ describe(':source', function()
feed('dd')
feed_command(':source')
local filepath = fn.expand('%:p')
if filepath == '' then
filepath = ':source buffer=1'
end
eq(12, eval('g:c'))
eq(' \\ 1\n "\\ 2', exec_lua('return _G.a'))
eq(':source buffer=1', api.nvim_get_var('sfile_value'))
eq(':source buffer=1', api.nvim_get_var('stack_value'))
eq(':source buffer=1', api.nvim_get_var('script_value'))
eq(filepath, api.nvim_get_var('sfile_value'))
eq(filepath, api.nvim_get_var('stack_value'))
eq(filepath, api.nvim_get_var('script_value'))
end)
end