aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-07-14 07:57:13 +0800
committerGitHub <noreply@github.com>2023-07-14 07:57:13 +0800
commit9176b5e10a6b32ff65c8ba3f532e3bd55c168ec6 (patch)
treec6ad5b716b04547789d252bd2f70882f7d8fad4d
parentdbb840da01c72d8a311e0c55d3248d78a64b63a4 (diff)
downloadrneovim-9176b5e10a6b32ff65c8ba3f532e3bd55c168ec6.tar.gz
rneovim-9176b5e10a6b32ff65c8ba3f532e3bd55c168ec6.tar.bz2
rneovim-9176b5e10a6b32ff65c8ba3f532e3bd55c168ec6.zip
fix(runtime): respect 'fileignorecase' when sourcing (#24344)
-rw-r--r--src/nvim/path.c2
-rw-r--r--src/nvim/runtime.c7
-rw-r--r--src/nvim/strings.c19
-rw-r--r--test/functional/lua/runtime_spec.lua25
-rw-r--r--test/unit/path_spec.lua10
5 files changed, 40 insertions, 23 deletions
diff --git a/src/nvim/path.c b/src/nvim/path.c
index 828b690699..d1e0947038 100644
--- a/src/nvim/path.c
+++ b/src/nvim/path.c
@@ -1810,7 +1810,7 @@ bool path_with_extension(const char *path, const char *extension)
if (!last_dot) {
return false;
}
- return strcmp(last_dot + 1, extension) == 0;
+ return mb_strcmp_ic((bool)p_fic, last_dot + 1, extension) == 0;
}
/// Return true if "name" is a full (absolute) path name or URL.
diff --git a/src/nvim/runtime.c b/src/nvim/runtime.c
index 9cd4a17b27..9614937c4c 100644
--- a/src/nvim/runtime.c
+++ b/src/nvim/runtime.c
@@ -275,7 +275,7 @@ static bool source_callback_vim_lua(int num_fnames, char **fnames, bool all, voi
bool did_one = false;
for (int i = 0; i < num_fnames; i++) {
- if (str_ends_with(fnames[i], ".vim")) {
+ if (path_with_extension(fnames[i], "vim")) {
(void)do_source(fnames[i], false, DOSO_NONE, cookie);
did_one = true;
if (!all) {
@@ -285,7 +285,7 @@ static bool source_callback_vim_lua(int num_fnames, char **fnames, bool all, voi
}
for (int i = 0; i < num_fnames; i++) {
- if (str_ends_with(fnames[i], ".lua")) {
+ if (path_with_extension(fnames[i], "lua")) {
(void)do_source(fnames[i], false, DOSO_NONE, cookie);
did_one = true;
if (!all) {
@@ -308,7 +308,8 @@ static bool source_callback(int num_fnames, char **fnames, bool all, void *cooki
}
for (int i = 0; i < num_fnames; i++) {
- if (!str_ends_with(fnames[i], ".vim") && !str_ends_with(fnames[i], ".lua")) {
+ if (!path_with_extension(fnames[i], "vim")
+ && !path_with_extension(fnames[i], "lua")) {
(void)do_source(fnames[i], false, DOSO_NONE, cookie);
did_one = true;
if (!all) {
diff --git a/src/nvim/strings.c b/src/nvim/strings.c
index 52a803a3cc..6fe2fd8ff3 100644
--- a/src/nvim/strings.c
+++ b/src/nvim/strings.c
@@ -436,25 +436,6 @@ char *vim_strchr(const char *const string, const int c)
}
}
-/// Test if "str" ends with "suffix"
-///
-/// @param[in] str
-/// @param[in] suffix to match
-///
-/// @return [allocated] Copy of the string.
-bool str_ends_with(const char *str, const char *suffix)
-{
- if (!str || !suffix) {
- return false;
- }
- size_t lenstr = strlen(str);
- size_t lensuffix = strlen(suffix);
- if (lensuffix > lenstr) {
- return false;
- }
- return strncmp(str + lenstr - lensuffix, suffix, lensuffix) == 0;
-}
-
// Sort an array of strings.
#ifdef INCLUDE_GENERATED_DECLARATIONS
diff --git a/test/functional/lua/runtime_spec.lua b/test/functional/lua/runtime_spec.lua
index 1f312fc513..0b8b2234db 100644
--- a/test/functional/lua/runtime_spec.lua
+++ b/test/functional/lua/runtime_spec.lua
@@ -177,6 +177,31 @@ describe('runtime:', function()
exec('setfiletype new-ft')
eq('ABCDEFabcdef', eval('g:seq'))
end)
+
+ it("'rtp' order is respected with 'fileignorecase'", function()
+ exec('set fileignorecase')
+ local after_ftplugin_folder = table.concat({plug_dir, 'after', 'ftplugin'}, sep)
+ mkdir_p(table.concat({ftplugin_folder, 'new-ft'}, sep))
+ mkdir_p(table.concat({after_ftplugin_folder, 'new-ft'}, sep))
+ exec('set rtp+=' .. plug_dir .. '/after')
+ exec('let g:seq = ""')
+ -- A .lua file is loaded after a .vim file if they only differ in extension.
+ -- All files in after/ftplugin/ are loaded after all files in ftplugin/.
+ write_file(table.concat({ftplugin_folder, 'new-ft.VIM'}, sep), [[let g:seq ..= 'A']])
+ write_file(table.concat({ftplugin_folder, 'new-ft.LUA'}, sep), [[vim.g.seq = vim.g.seq .. 'B']])
+ write_file(table.concat({ftplugin_folder, 'new-ft_a.vim'}, sep), [[let g:seq ..= 'C']])
+ write_file(table.concat({ftplugin_folder, 'new-ft_a.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'D']])
+ write_file(table.concat({ftplugin_folder, 'new-ft', 'a.VIM'}, sep), [[let g:seq ..= 'E']])
+ write_file(table.concat({ftplugin_folder, 'new-ft', 'a.LUA'}, sep), [[vim.g.seq = vim.g.seq .. 'F']])
+ write_file(table.concat({after_ftplugin_folder, 'new-ft.vim'}, sep), [[let g:seq ..= 'a']])
+ write_file(table.concat({after_ftplugin_folder, 'new-ft.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'b']])
+ write_file(table.concat({after_ftplugin_folder, 'new-ft_a.VIM'}, sep), [[let g:seq ..= 'c']])
+ write_file(table.concat({after_ftplugin_folder, 'new-ft_a.LUA'}, sep), [[vim.g.seq = vim.g.seq .. 'd']])
+ write_file(table.concat({after_ftplugin_folder, 'new-ft', 'a.vim'}, sep), [[let g:seq ..= 'e']])
+ write_file(table.concat({after_ftplugin_folder, 'new-ft', 'a.lua'}, sep), [[vim.g.seq = vim.g.seq .. 'f']])
+ exec('setfiletype new-ft')
+ eq('ABCDEFabcdef', eval('g:seq'))
+ end)
end)
describe('indent', function()
diff --git a/test/unit/path_spec.lua b/test/unit/path_spec.lua
index 5808e2013a..f9ce1ff099 100644
--- a/test/unit/path_spec.lua
+++ b/test/unit/path_spec.lua
@@ -15,6 +15,7 @@ local mkdir = helpers.mkdir
cimport('string.h')
local cimp = cimport('./src/nvim/os/os.h', './src/nvim/path.h')
+local options = cimport('./src/nvim/option_defs.h')
local length = 0
local buffer = nil
@@ -636,6 +637,15 @@ describe('path.c', function()
eq(false, path_with_extension('/some/path/file.vim', 'lua'))
eq(false, path_with_extension('/some/path/file', 'lua'))
end)
+
+ itp("respects 'fileignorecase' option", function()
+ options.p_fic = false
+ eq(false, path_with_extension('/some/path/file.VIM', 'vim'))
+ eq(false, path_with_extension('/some/path/file.LUA', 'lua'))
+ options.p_fic = true
+ eq(true, path_with_extension('/some/path/file.VIM', 'vim'))
+ eq(true, path_with_extension('/some/path/file.LUA', 'lua'))
+ end)
end)
describe('path_with_url', function()