fix: issue with special char in new filename (closes #178)

This commit is contained in:
Thomas Lambert
2022-11-08 20:44:28 +01:00
parent 60808e8e59
commit de4502bd55

View File

@@ -168,6 +168,11 @@ local function defaultConfig(home)
} }
end end
--- escapes a string for use as exact pattern within gsub
local function escape(s)
return string.gsub(s, "[%%%]%^%-$().[*+?]", "%%%1")
end
local function file_exists(fname) local function file_exists(fname)
if fname == nil then if fname == nil then
return false return false
@@ -207,7 +212,7 @@ local function generate_note_filename(uuid, title)
local pp = Path:new(title) local pp = Path:new(title)
local p_splits = pp:_split() local p_splits = pp:_split()
local filename = p_splits[#p_splits] local filename = p_splits[#p_splits]
local subdir = title:gsub(filename, "") local subdir = title:gsub(escape(filename), "")
local sep = M.Cfg.uuid_sep or "-" local sep = M.Cfg.uuid_sep or "-"
if M.Cfg.new_note_filename ~= "uuid" and #title > 0 then if M.Cfg.new_note_filename ~= "uuid" and #title > 0 then
@@ -275,11 +280,6 @@ local function global_dir_check()
return ret return ret
end end
--- escapes a string for use as exact pattern within gsub
local function escape(s)
return string.gsub(s, "[%%%]%^%-$().[*+?]", "%%%1")
end
local function make_config_path_absolute(path) local function make_config_path_absolute(path)
local ret = path local ret = path
if not (Path:new(path):is_absolute()) and path ~= nil then if not (Path:new(path):is_absolute()) and path ~= nil then