From 4b4c54ba65fb78d73611e11ed4ba6bb406dabee3 Mon Sep 17 00:00:00 2001 From: Guldoman Date: Tue, 16 Aug 2022 08:08:04 +0200 Subject: [PATCH] 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)