From 1e7e9ee91f73c62b8c5ba9dbdabba3a3b6dc0130 Mon Sep 17 00:00:00 2001 From: Leonardo Mello Date: Tue, 3 Oct 2023 19:04:19 -0300 Subject: fix(path): accept special characters on Windows (#25424) --- test/functional/core/path_spec.lua | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'test/functional/core/path_spec.lua') diff --git a/test/functional/core/path_spec.lua b/test/functional/core/path_spec.lua index a786887bbd..6c677d76d1 100644 --- a/test/functional/core/path_spec.lua +++ b/test/functional/core/path_spec.lua @@ -6,16 +6,19 @@ local command = helpers.command local insert = helpers.insert local feed = helpers.feed local is_os = helpers.is_os +local mkdir = helpers.mkdir +local rmdir = helpers.rmdir +local write_file = helpers.write_file + +local function join_path(...) + local pathsep = (is_os('win') and '\\' or '/') + return table.concat({...}, pathsep) +end describe('path collapse', function() local targetdir local expected_path - local function join_path(...) - local pathsep = (is_os('win') and '\\' or '/') - return table.concat({...}, pathsep) - end - before_each(function() targetdir = join_path('test', 'functional', 'fixtures') clear() @@ -57,6 +60,27 @@ describe('path collapse', function() end) end) +describe('expand wildcard', function() + before_each(clear) + + it('with special characters #24421', function() + local folders = is_os('win') and { + '{folder}', + 'folder$name' + } or { + 'folder-name', + 'folder#name' + } + for _, folder in ipairs(folders) do + mkdir(folder) + local file = join_path(folder, 'file.txt') + write_file(file, '') + eq(file, eval('expand("'..folder..'/*")')) + rmdir(folder) + end + end) +end) + describe('file search', function() before_each(clear) -- cgit From 1dd700a8d9275439fbc71ac5adeb59914bdbd5cf Mon Sep 17 00:00:00 2001 From: Leonardo Mello Date: Mon, 18 Sep 2023 16:50:47 -0300 Subject: fix: gf fails on "foo/bar.txt:1:2" on Windows Problem: On Windows, "gf" fails on a filepath that has a line:column suffix. Example: E447: Can't find file "src/app/core/services/identity/identity.service.ts:64:23" Solution: - Remove ":" from 'isfname' on Windows. Colon is not a valid filename character (except for the drive-letter). - Handle drive letters specially in file_name_in_line(). Fixes #25160 --- test/functional/core/path_spec.lua | 76 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) (limited to 'test/functional/core/path_spec.lua') diff --git a/test/functional/core/path_spec.lua b/test/functional/core/path_spec.lua index 6c677d76d1..1c6faf8d60 100644 --- a/test/functional/core/path_spec.lua +++ b/test/functional/core/path_spec.lua @@ -91,4 +91,80 @@ describe('file search', function() feed('gf') eq('filename_with_unicode_ααα', eval('expand("%:t")')) end) + + it('matches Windows drive-letter filepaths (without ":" in &isfname)', function() + local os_win = is_os('win') + + insert([[c:/d:/foo/bar.txt]]) + eq([[c:/d:/foo/bar.txt]], eval('expand("")')) + command('%delete') + + insert([[//share/c:/foo/bar/]]) + eq([[//share/c:/foo/bar/]], eval('expand("")')) + command('%delete') + + insert([[file://c:/foo/bar]]) + eq([[file://c:/foo/bar]], eval('expand("")')) + command('%delete') + + insert([[https://c:/foo/bar]]) + eq([[https://c:/foo/bar]], eval('expand("")')) + command('%delete') + + insert([[\foo\bar]]) + eq(os_win and [[\foo\bar]] or [[bar]], eval('expand("")')) + command('%delete') + + insert([[/foo/bar]]) + eq([[/foo/bar]], eval('expand("")')) + command('%delete') + + insert([[c:\foo\bar]]) + eq(os_win and [[c:\foo\bar]] or [[bar]], eval('expand("")')) + command('%delete') + + insert([[c:/foo/bar]]) + eq([[c:/foo/bar]], eval('expand("")')) + command('%delete') + + insert([[c:foo\bar]]) + eq(os_win and [[foo\bar]] or [[bar]], eval('expand("")')) + command('%delete') + + insert([[c:foo/bar]]) + eq([[foo/bar]], eval('expand("")')) + command('%delete') + + insert([[c:foo]]) + eq([[foo]], eval('expand("")')) + command('%delete') + + -- Examples from: https://learn.microsoft.com/en-us/dotnet/standard/io/file-path-formats#example-ways-to-refer-to-the-same-file + insert([[c:\temp\test-file.txt]]) + eq(os_win and [[c:\temp\test-file.txt]] or [[test-file.txt]], eval('expand("")')) + command('%delete') + + insert([[\\127.0.0.1\c$\temp\test-file.txt]]) + eq(os_win and [[\\127.0.0.1\c$\temp\test-file.txt]] or [[test-file.txt]], eval('expand("")')) + command('%delete') + + insert([[\\LOCALHOST\c$\temp\test-file.txt]]) + eq(os_win and [[\\LOCALHOST\c$\temp\test-file.txt]] or [[test-file.txt]], eval('expand("")')) + command('%delete') + + insert([[\\.\c:\temp\test-file.txt]]) -- not supported yet + eq(os_win and [[\\.\c]] or [[test-file.txt]], eval('expand("")')) + command('%delete') + + insert([[\\?\c:\temp\test-file.txt]]) -- not supported yet + eq(os_win and [[\c]] or [[test-file.txt]], eval('expand("")')) + command('%delete') + + insert([[\\.\UNC\LOCALHOST\c$\temp\test-file.txt]]) + eq(os_win and [[\\.\UNC\LOCALHOST\c$\temp\test-file.txt]] or [[test-file.txt]], eval('expand("")')) + command('%delete') + + insert([[\\127.0.0.1\c$\temp\test-file.txt]]) + eq(os_win and [[\\127.0.0.1\c$\temp\test-file.txt]] or [[test-file.txt]], eval('expand("")')) + end) end) -- cgit From 133e2990efa44cadf1410a452a08843dbd8ca86e Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 6 Oct 2023 12:59:39 +0200 Subject: refactor: cleanup --- test/functional/core/path_spec.lua | 106 ++++++++++++------------------------- 1 file changed, 34 insertions(+), 72 deletions(-) (limited to 'test/functional/core/path_spec.lua') diff --git a/test/functional/core/path_spec.lua b/test/functional/core/path_spec.lua index 1c6faf8d60..06fa13dca5 100644 --- a/test/functional/core/path_spec.lua +++ b/test/functional/core/path_spec.lua @@ -81,7 +81,7 @@ describe('expand wildcard', function() end) end) -describe('file search', function() +describe('file search (gf, )', function() before_each(clear) it('find multibyte file name in line #20517', function() @@ -93,78 +93,40 @@ describe('file search', function() end) it('matches Windows drive-letter filepaths (without ":" in &isfname)', function() - local os_win = is_os('win') - - insert([[c:/d:/foo/bar.txt]]) - eq([[c:/d:/foo/bar.txt]], eval('expand("")')) - command('%delete') - - insert([[//share/c:/foo/bar/]]) - eq([[//share/c:/foo/bar/]], eval('expand("")')) - command('%delete') - - insert([[file://c:/foo/bar]]) - eq([[file://c:/foo/bar]], eval('expand("")')) - command('%delete') - - insert([[https://c:/foo/bar]]) - eq([[https://c:/foo/bar]], eval('expand("")')) - command('%delete') - - insert([[\foo\bar]]) - eq(os_win and [[\foo\bar]] or [[bar]], eval('expand("")')) - command('%delete') - - insert([[/foo/bar]]) - eq([[/foo/bar]], eval('expand("")')) - command('%delete') - - insert([[c:\foo\bar]]) - eq(os_win and [[c:\foo\bar]] or [[bar]], eval('expand("")')) - command('%delete') - - insert([[c:/foo/bar]]) - eq([[c:/foo/bar]], eval('expand("")')) - command('%delete') - - insert([[c:foo\bar]]) - eq(os_win and [[foo\bar]] or [[bar]], eval('expand("")')) - command('%delete') - - insert([[c:foo/bar]]) - eq([[foo/bar]], eval('expand("")')) - command('%delete') - - insert([[c:foo]]) - eq([[foo]], eval('expand("")')) - command('%delete') + local iswin = is_os('win') + local function test_cfile(input, expected, expected_win) + expected = (iswin and expected_win or expected) or input + command('%delete') + insert(input) + command('norm! 0') + eq(expected, eval('expand("")')) + end + test_cfile([[c:/d:/foo/bar.txt]]) -- TODO(justinmk): should return "d:/foo/bar.txt" ? + test_cfile([[//share/c:/foo/bar/]]) + test_cfile([[file://c:/foo/bar]]) + test_cfile([[file://c:/foo/bar:42]]) + test_cfile([[file://c:/foo/bar:42:666]]) + test_cfile([[https://c:/foo/bar]]) + test_cfile([[\foo\bar]], [[foo]], [[\foo\bar]]) + test_cfile([[/foo/bar]], [[/foo/bar]]) + test_cfile([[c:\foo\bar]], [[c:]], [[c:\foo\bar]]) + test_cfile([[c:\foo\bar:42:666]], [[c:]], [[c:\foo\bar]]) + test_cfile([[c:/foo/bar]]) + test_cfile([[c:/foo/bar:42]], [[c:/foo/bar]]) + test_cfile([[c:/foo/bar:42:666]], [[c:/foo/bar]]) + test_cfile([[c:foo\bar]], [[c]]) + test_cfile([[c:foo/bar]], [[c]]) + test_cfile([[c:foo]], [[c]]) -- Examples from: https://learn.microsoft.com/en-us/dotnet/standard/io/file-path-formats#example-ways-to-refer-to-the-same-file - insert([[c:\temp\test-file.txt]]) - eq(os_win and [[c:\temp\test-file.txt]] or [[test-file.txt]], eval('expand("")')) - command('%delete') - - insert([[\\127.0.0.1\c$\temp\test-file.txt]]) - eq(os_win and [[\\127.0.0.1\c$\temp\test-file.txt]] or [[test-file.txt]], eval('expand("")')) - command('%delete') - - insert([[\\LOCALHOST\c$\temp\test-file.txt]]) - eq(os_win and [[\\LOCALHOST\c$\temp\test-file.txt]] or [[test-file.txt]], eval('expand("")')) - command('%delete') - - insert([[\\.\c:\temp\test-file.txt]]) -- not supported yet - eq(os_win and [[\\.\c]] or [[test-file.txt]], eval('expand("")')) - command('%delete') - - insert([[\\?\c:\temp\test-file.txt]]) -- not supported yet - eq(os_win and [[\c]] or [[test-file.txt]], eval('expand("")')) - command('%delete') - - insert([[\\.\UNC\LOCALHOST\c$\temp\test-file.txt]]) - eq(os_win and [[\\.\UNC\LOCALHOST\c$\temp\test-file.txt]] or [[test-file.txt]], eval('expand("")')) - command('%delete') - - insert([[\\127.0.0.1\c$\temp\test-file.txt]]) - eq(os_win and [[\\127.0.0.1\c$\temp\test-file.txt]] or [[test-file.txt]], eval('expand("")')) + test_cfile([[c:\temp\test-file.txt]], [[c:]], [[c:\temp\test-file.txt]]) + test_cfile([[\\127.0.0.1\c$\temp\test-file.txt]], [[127.0.0.1]], [[\\127.0.0.1\c$\temp\test-file.txt]]) + test_cfile([[\\LOCALHOST\c$\temp\test-file.txt]], [[LOCALHOST]], [[\\LOCALHOST\c$\temp\test-file.txt]]) + -- not supported yet + test_cfile([[\\.\c:\temp\test-file.txt]], [[.]], [[\\.\c]]) + -- not supported yet + test_cfile([[\\?\c:\temp\test-file.txt]], [[c:]], [[\\]]) + test_cfile([[\\.\UNC\LOCALHOST\c$\temp\test-file.txt]], [[.]], [[\\.\UNC\LOCALHOST\c$\temp\test-file.txt]]) + test_cfile([[\\127.0.0.1\c$\temp\test-file.txt]], [[127.0.0.1]], [[\\127.0.0.1\c$\temp\test-file.txt]]) end) end) -- cgit From 81f67b79e8a307a45a996dbeee0213c7745aa358 Mon Sep 17 00:00:00 2001 From: Leonardo Mello Date: Mon, 9 Oct 2023 19:08:58 -0300 Subject: fix(file_search): path with spaces in finddir() and findfile() (#25493) Co-authored-by: dundargoc --- test/functional/core/path_spec.lua | 41 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) (limited to 'test/functional/core/path_spec.lua') diff --git a/test/functional/core/path_spec.lua b/test/functional/core/path_spec.lua index 06fa13dca5..215217e771 100644 --- a/test/functional/core/path_spec.lua +++ b/test/functional/core/path_spec.lua @@ -1,10 +1,10 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear +local command = helpers.command local eq = helpers.eq local eval = helpers.eval -local command = helpers.command -local insert = helpers.insert local feed = helpers.feed +local insert = helpers.insert local is_os = helpers.is_os local mkdir = helpers.mkdir local rmdir = helpers.rmdir @@ -130,3 +130,40 @@ describe('file search (gf, )', function() test_cfile([[\\127.0.0.1\c$\temp\test-file.txt]], [[127.0.0.1]], [[\\127.0.0.1\c$\temp\test-file.txt]]) end) end) + +describe('file search with vim functions', function() + local test_folder = "path_spec_folder" + + setup(function() + mkdir(test_folder) + end) + + teardown(function() + rmdir(test_folder) + end) + + ---@param option "dir" | "file" + local function test_find_func(option, folder, item) + local folder_path = join_path(test_folder, folder) + mkdir(folder_path) + local expected = join_path(folder_path, item) + if option == "dir" then + mkdir(expected) + else + write_file(expected, '') + end + eq(expected, eval('find'..option..'(fnameescape(\''..item..'\'),fnameescape(\''..folder_path..'\'))')) + end + + it('finddir()', function() + test_find_func('dir', 'directory', 'folder') + -- test_find_func('dir', 'directory', 'folder name') + test_find_func('dir', 'folder name', 'directory') + end) + + it('findfile()', function() + test_find_func('file', 'directory', 'file.txt') + -- test_find_func('file', 'directory', 'file name.txt') + test_find_func('file', 'folder name', 'file.txt') + end) +end) -- cgit From 4eea60939f9c079d4e1652e0ed1724c4f2ab6eda Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 11 Oct 2023 07:24:37 +0800 Subject: test(core/path_spec): don't use fnameescape() (#25593) Using fnameescape() for the path argument of findfile() and finddir() is wrong, as fnameescape() is intended to be used for parts of Ex commands, not function arguments. --- test/functional/core/path_spec.lua | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'test/functional/core/path_spec.lua') diff --git a/test/functional/core/path_spec.lua b/test/functional/core/path_spec.lua index 215217e771..268d557691 100644 --- a/test/functional/core/path_spec.lua +++ b/test/functional/core/path_spec.lua @@ -4,6 +4,7 @@ local command = helpers.command local eq = helpers.eq local eval = helpers.eval local feed = helpers.feed +local funcs = helpers.funcs local insert = helpers.insert local is_os = helpers.is_os local mkdir = helpers.mkdir @@ -152,18 +153,18 @@ describe('file search with vim functions', function() else write_file(expected, '') end - eq(expected, eval('find'..option..'(fnameescape(\''..item..'\'),fnameescape(\''..folder_path..'\'))')) + eq(expected, funcs['find' .. option](item, folder_path:gsub(' ', [[\ ]]))) end it('finddir()', function() test_find_func('dir', 'directory', 'folder') - -- test_find_func('dir', 'directory', 'folder name') - test_find_func('dir', 'folder name', 'directory') + test_find_func('dir', 'directory', 'folder name') + test_find_func('dir', 'fold#er name', 'directory') end) it('findfile()', function() test_find_func('file', 'directory', 'file.txt') - -- test_find_func('file', 'directory', 'file name.txt') - test_find_func('file', 'folder name', 'file.txt') + test_find_func('file', 'directory', 'file name.txt') + test_find_func('file', 'fold#er name', 'file.txt') end) end) -- cgit From 2c9f22e7e4947e1865ab18c61fbc0199be8b323d Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 12 Oct 2023 07:04:16 -0700 Subject: refactor(test): cleanup #25614 - unnecessary separate describe() group - clear() wasn't called in the describe() group - unnecessary indirection in function parameters --- test/functional/core/path_spec.lua | 54 ++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 28 deletions(-) (limited to 'test/functional/core/path_spec.lua') diff --git a/test/functional/core/path_spec.lua b/test/functional/core/path_spec.lua index 268d557691..97c32f7de6 100644 --- a/test/functional/core/path_spec.lua +++ b/test/functional/core/path_spec.lua @@ -82,10 +82,20 @@ describe('expand wildcard', function() end) end) -describe('file search (gf, )', function() +describe('file search', function() + local testdir = 'Xtest_path_spec' + before_each(clear) - it('find multibyte file name in line #20517', function() + setup(function() + mkdir(testdir) + end) + + teardown(function() + rmdir(testdir) + end) + + it('gf finds multibyte filename in line #20517', function() command('cd test/functional/fixtures') insert('filename_with_unicode_ααα') eq('', eval('expand("%")')) @@ -93,7 +103,7 @@ describe('file search (gf, )', function() eq('filename_with_unicode_ααα', eval('expand("%:t")')) end) - it('matches Windows drive-letter filepaths (without ":" in &isfname)', function() + it('gf/ matches Windows drive-letter filepaths (without ":" in &isfname)', function() local iswin = is_os('win') local function test_cfile(input, expected, expected_win) expected = (iswin and expected_win or expected) or input @@ -130,41 +140,29 @@ describe('file search (gf, )', function() test_cfile([[\\.\UNC\LOCALHOST\c$\temp\test-file.txt]], [[.]], [[\\.\UNC\LOCALHOST\c$\temp\test-file.txt]]) test_cfile([[\\127.0.0.1\c$\temp\test-file.txt]], [[127.0.0.1]], [[\\127.0.0.1\c$\temp\test-file.txt]]) end) -end) - -describe('file search with vim functions', function() - local test_folder = "path_spec_folder" - - setup(function() - mkdir(test_folder) - end) - - teardown(function() - rmdir(test_folder) - end) - ---@param option "dir" | "file" - local function test_find_func(option, folder, item) - local folder_path = join_path(test_folder, folder) - mkdir(folder_path) - local expected = join_path(folder_path, item) - if option == "dir" then + ---@param funcname 'finddir' | 'findfile' + local function test_find_func(funcname, folder, item) + local d = join_path(testdir, folder) + mkdir(d) + local expected = join_path(d, item) + if funcname == 'finddir' then mkdir(expected) else write_file(expected, '') end - eq(expected, funcs['find' .. option](item, folder_path:gsub(' ', [[\ ]]))) + eq(expected, funcs[funcname](item, d:gsub(' ', [[\ ]]))) end it('finddir()', function() - test_find_func('dir', 'directory', 'folder') - test_find_func('dir', 'directory', 'folder name') - test_find_func('dir', 'fold#er name', 'directory') + test_find_func('finddir', 'directory', 'folder') + test_find_func('finddir', 'directory', 'folder name') + test_find_func('finddir', 'fold#er name', 'directory') end) it('findfile()', function() - test_find_func('file', 'directory', 'file.txt') - test_find_func('file', 'directory', 'file name.txt') - test_find_func('file', 'fold#er name', 'file.txt') + test_find_func('findfile', 'directory', 'file.txt') + test_find_func('findfile', 'directory', 'file name.txt') + test_find_func('findfile', 'fold#er name', 'file.txt') end) end) -- cgit