From 4b4c54ba65fb78d73611e11ed4ba6bb406dabee3 Mon Sep 17 00:00:00 2001 From: Guldoman Date: Tue, 16 Aug 2022 08:08:04 +0200 Subject: [PATCH 1/4] Remove dot slash from suggested paths in `common.path_suggest` When no `root` is specified and the initial `path` is empty, the initial `path` becomes `.`. This results in returned files/dirs that are prepended with `./`. Now, in that case, `./` is removed. --- data/core/common.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/data/core/common.lua b/data/core/common.lua index b65db6b9..82927216 100644 --- a/data/core/common.lua +++ b/data/core/common.lua @@ -152,11 +152,13 @@ function common.path_suggest(text, root) root = root .. PATHSEP end local path, name = text:match("^(.-)([^/\\]*)$") + local clean_dotslash = false -- ignore root if path is absolute local is_absolute = common.is_absolute_path(text) if not is_absolute then if path == "" then path = root or "." + clean_dotslash = not root else path = (root or "") .. path end @@ -180,6 +182,12 @@ function common.path_suggest(text, root) if s == 1 then file = file:sub(e + 1) end + elseif clean_dotslash then + -- remove added dot slash + local s, e = file:find("." .. PATHSEP, nil, true) + if s == 1 then + file = file:sub(e + 1) + end end if file:lower():find(text:lower(), nil, true) == 1 then table.insert(res, file) From a4355c6536364d25d2a500d1959c9a3b9e2bc247 Mon Sep 17 00:00:00 2001 From: Guldoman Date: Tue, 16 Aug 2022 23:51:12 +0200 Subject: [PATCH 2/4] Add `PATHSEP` before listing the directory in `common.path_suggest` Before, in Windows, listing `.` instead of `.\` resulted in unexpected results. --- data/core/common.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/core/common.lua b/data/core/common.lua index 82927216..c7932455 100644 --- a/data/core/common.lua +++ b/data/core/common.lua @@ -164,10 +164,10 @@ function common.path_suggest(text, root) end end - local files = system.list_dir(path) or {} if path:sub(-1) ~= PATHSEP then path = path .. PATHSEP end + local files = system.list_dir(path) or {} local res = {} for _, file in ipairs(files) do file = path .. file From e8ca861512e8e6c2ba343e16e524b163eb506190 Mon Sep 17 00:00:00 2001 From: Guldoman Date: Tue, 16 Aug 2022 23:53:03 +0200 Subject: [PATCH 3/4] Remove final `PATHSEP` in `common.normalize_volume` --- data/core/common.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data/core/common.lua b/data/core/common.lua index c7932455..5406f170 100644 --- a/data/core/common.lua +++ b/data/core/common.lua @@ -370,11 +370,11 @@ end -- absolute path without . or .. elements. -- This function exists because on Windows the drive letter returned -- by system.absolute_path is sometimes with a lower case and sometimes --- with an upper case to we normalize to upper case. +-- with an upper case so we normalize to upper case. function common.normalize_volume(filename) if not filename then return end if PATHSEP == '\\' then - local drive, rem = filename:match('^([a-zA-Z]:\\)(.*)') + local drive, rem = filename:match('^([a-zA-Z]:\\)(.-)'..PATHSEP..'?$') if drive then return drive:upper() .. rem end From 4c186b07a33f0cdabc22690ffc36cabb961b32a1 Mon Sep 17 00:00:00 2001 From: Guldoman Date: Wed, 17 Aug 2022 00:11:19 +0200 Subject: [PATCH 4/4] Be more lenient with appending `PATHSEP` in `common.path_suggest` in Windows This allows to use the Unix separator without resulting in ugly suggestions that added the Windows separator too. For example: Before: `data/` -> `data/\core\` After: `data/` -> `data/core\` --- data/core/common.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/data/core/common.lua b/data/core/common.lua index 5406f170..a4ea01f5 100644 --- a/data/core/common.lua +++ b/data/core/common.lua @@ -164,7 +164,9 @@ function common.path_suggest(text, root) end end - if path:sub(-1) ~= PATHSEP then + -- Only in Windows allow using both styles of PATHSEP + if (PATHSEP == "\\" and not string.match(path:sub(-1), "[\\/]")) or + (PATHSEP ~= "\\" and path:sub(-1) ~= PATHSEP) then path = path .. PATHSEP end local files = system.list_dir(path) or {}