From 420af110a8afb0853f588e565ca27dfccd7f8664 Mon Sep 17 00:00:00 2001 From: Trevor Richards Date: Fri, 24 Mar 2023 23:45:05 -0700 Subject: [PATCH 1/2] fix: guard against incompatible root paths This commit fixes paths that are made from ~/Home and/or have a trailing slash --- lua/wiki/init.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lua/wiki/init.lua b/lua/wiki/init.lua index 1329cdb..a93e38a 100644 --- a/lua/wiki/init.lua +++ b/lua/wiki/init.lua @@ -2,7 +2,9 @@ local M = {} -- Returns shorten path local function filter(path) - local root = vim.g.wiki_root .. "/" + local root = vim.fn + .substitute(vim.fn + .expand(vim.g.wiki_root .. "/"), "\\/$", "", nil) return path:gsub(root, "") end From b4834fd66993a1286d1590b973f7f830295ec7f0 Mon Sep 17 00:00:00 2001 From: Trevor Richards Date: Fri, 24 Mar 2023 23:51:51 -0700 Subject: [PATCH 2/2] chore: pull normalization out of filter function Filter's now doing too much --- lua/wiki/init.lua | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lua/wiki/init.lua b/lua/wiki/init.lua index a93e38a..50e2f91 100644 --- a/lua/wiki/init.lua +++ b/lua/wiki/init.lua @@ -1,10 +1,12 @@ local M = {} +local function normalize_path(path) + return vim.fn.substitute(vim.fn.expand(vim.g.wiki_root .. "/"), "\\/$", "", nil) +end + -- Returns shorten path local function filter(path) - local root = vim.fn - .substitute(vim.fn - .expand(vim.g.wiki_root .. "/"), "\\/$", "", nil) + local root = normalize_path(path) return path:gsub(root, "") end