diff src/vim9script.c @ 35012:890b693189b0 v9.1.0359

patch 9.1.0359: MS-Windows: relative import in a script sourced from a buffer doesn't work Commit: https://github.com/vim/vim/commit/f135fa28e481b2eba73baf52b08d24add5c4fe8b Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Sat Apr 20 18:31:21 2024 +0200 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 #14588 closes: #14603 Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Sat, 20 Apr 2024 18:45:02 +0200
parents 695b50472e85
children
line wrap: on
line diff
--- a/src/vim9script.c
+++ b/src/vim9script.c
@@ -456,15 +456,24 @@ handle_import(
 	scriptitem_T	*si = SCRIPT_ITEM(current_sctx.sc_sid);
 	char_u		*tail = gettail(si->sn_name);
 	char_u		*from_name;
+	int		sourced_from_nofile_buf = FALSE;
 
-	// Relative to current script: "./name.vim", "../../name.vim".
-	len = STRLEN(si->sn_name) - STRLEN(tail) + STRLEN(tv.vval.v_string) + 2;
-	from_name = alloc((int)len);
-	if (from_name == NULL)
-	    goto erret;
-	vim_strncpy(from_name, si->sn_name, tail - si->sn_name);
-	add_pathsep(from_name);
-	STRCAT(from_name, tv.vval.v_string);
+	if (STRNCMP(si->sn_name, ":source buffer=", 15) == 0)
+	    sourced_from_nofile_buf = TRUE;
+
+	if (!sourced_from_nofile_buf)
+	{
+	    // Relative to current script: "./name.vim", "../../name.vim".
+	    len = STRLEN(si->sn_name) - STRLEN(tail) + STRLEN(tv.vval.v_string) + 2;
+	    from_name = alloc((int)len);
+	    if (from_name == NULL)
+		goto erret;
+	    vim_strncpy(from_name, si->sn_name, tail - si->sn_name);
+	    add_pathsep(from_name);
+	    STRCAT(from_name, tv.vval.v_string);
+	}
+	else
+	    from_name = vim_strsave(tv.vval.v_string);
 	simplify_filename(from_name);
 
 	res = handle_import_fname(from_name, is_autoload, &sid);