mirror of
https://github.com/Ascyii/telekasten.nvim.git
synced 2026-01-01 06:14:23 -05:00
Sanitize sed input
This commit is contained in:
@@ -206,6 +206,26 @@ local function escape(s)
|
|||||||
return string.gsub(s, "[%%%]%^%-$().[*+?]", "%%%1")
|
return string.gsub(s, "[%%%]%^%-$().[*+?]", "%%%1")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- sanitize strings
|
||||||
|
local escape_chars = function(string)
|
||||||
|
return string.gsub(string, "[%(|%)|\\|%[|%]|%-|%{%}|%?|%+|%*|%^|%$|%/]", {
|
||||||
|
["\\"] = "\\\\",
|
||||||
|
["-"] = "\\-",
|
||||||
|
["("] = "\\(",
|
||||||
|
[")"] = "\\)",
|
||||||
|
["["] = "\\[",
|
||||||
|
["]"] = "\\]",
|
||||||
|
["{"] = "\\{",
|
||||||
|
["}"] = "\\}",
|
||||||
|
["?"] = "\\?",
|
||||||
|
["+"] = "\\+",
|
||||||
|
["*"] = "\\*",
|
||||||
|
["^"] = "\\^",
|
||||||
|
["$"] = "\\$",
|
||||||
|
["/"] = "\\/",
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
local function recursive_substitution(dir, old, new)
|
local function recursive_substitution(dir, old, new)
|
||||||
if not global_dir_check() then
|
if not global_dir_check() then
|
||||||
return
|
return
|
||||||
@@ -220,17 +240,21 @@ local function recursive_substitution(dir, old, new)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
os.execute(
|
old = escape_chars(old)
|
||||||
"find "
|
new = escape_chars(new)
|
||||||
.. dir
|
|
||||||
.. " -type f -name '*"
|
local replace_cmd = "find "
|
||||||
.. M.Cfg.extension
|
.. dir
|
||||||
.. "' -exec sed -i 's|"
|
.. " -type f -name '*"
|
||||||
.. old
|
.. M.Cfg.extension
|
||||||
.. "|"
|
.. "' -exec sed -i 's/"
|
||||||
.. new
|
.. old
|
||||||
.. "|g' {} +"
|
.. "/"
|
||||||
)
|
.. new
|
||||||
|
.. "/g' {} +"
|
||||||
|
|
||||||
|
print(replace_cmd)
|
||||||
|
os.execute(replace_cmd)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function save_all_tk_buffers()
|
local function save_all_tk_buffers()
|
||||||
@@ -1477,8 +1501,8 @@ local function RenameNote()
|
|||||||
if M.Cfg.rename_update_links == true then
|
if M.Cfg.rename_update_links == true then
|
||||||
-- Only look for the first part of the link, so we do not touch to #heading or #^paragraph
|
-- Only look for the first part of the link, so we do not touch to #heading or #^paragraph
|
||||||
-- Should use regex instead to ensure it is a proper link
|
-- Should use regex instead to ensure it is a proper link
|
||||||
local oldlink = "\\[\\[" .. oldfile.title
|
local oldlink = "[[" .. oldfile.title
|
||||||
local newlink = "\\[\\[" .. newname
|
local newlink = "[[" .. newname
|
||||||
|
|
||||||
-- Save open telekasten buffers before looking for links to replace
|
-- Save open telekasten buffers before looking for links to replace
|
||||||
if
|
if
|
||||||
|
|||||||
Reference in New Issue
Block a user