From adbb23fce05b58108738913990d520994b0b9076 Mon Sep 17 00:00:00 2001 From: Damian Monogue <3660+demonnic@users.noreply.github.com> Date: Sun, 2 Oct 2022 18:14:04 -0400 Subject: [PATCH] Prevent forbidden characters from sneaking into filenames (#40) * Prevent forbidden characters from sneaking into filenamees derived from the loggingconsole's name * Also prevent invalid filename chars in the emco config save file * Apply filter to emco name and tabname --- mfile | 2 +- src/resources/emco.lua | 6 +++--- src/resources/loggingconsole.lua | 2 ++ src/resources/mdkversion.txt | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/mfile b/mfile index b3751de..054c300 100644 --- a/mfile +++ b/mfile @@ -1,6 +1,6 @@ { "package": "MDK", - "version": "2.7.0", + "version": "2.7.1", "author": "Demonnic", "title": "Collection of useful objects/classes", "icon": "computer.png", diff --git a/src/resources/emco.lua b/src/resources/emco.lua index c6f1d41..9b9780e 100644 --- a/src/resources/emco.lua +++ b/src/resources/emco.lua @@ -846,8 +846,8 @@ end -- @param str the string to replace tokens in -- @param tabName optional, if included will be used for |N in the templated string. function EMCO:processTemplate(str, tabName) - str = str:gsub("|E", self.name) - str = str:gsub("|N", tabName or "") + str = str:gsub("|E", self.name:gsub("[<>:'\"/|\\?*]", "_")) + str = str:gsub("|N", tabName:gsub("[<>:'\"/|\\?*]", "_") or "") return str end @@ -2127,7 +2127,7 @@ function EMCO:save() notifyWithFocus = self.notifyWithFocus, } local dirname = getMudletHomeDir() .. "/EMCO/" - local filename = dirname .. self.name .. ".lua" + local filename = dirname .. self.name:gsub("[<>:'\"/\\|?*]", "_") .. ".lua" if not (io.exists(dirname)) then lfs.mkdir(dirname) end diff --git a/src/resources/loggingconsole.lua b/src/resources/loggingconsole.lua index 3efd8d5..ec7849f 100644 --- a/src/resources/loggingconsole.lua +++ b/src/resources/loggingconsole.lua @@ -109,6 +109,7 @@ end --- Returns the filename for the logfile for this console function LoggingConsole:getFileName() local fileName = self:transformTemplate(self.fileName) + fileName = fileName:gsub("[<>:'\"/\\?*]", "_") return fileName end @@ -123,6 +124,7 @@ function LoggingConsole:getFullFilename() local path = self:getPath() local fileName = self:getFileName() local fullPath = path .. fileName + fullPath = fullPath:gsub("|", "_") return fullPath end diff --git a/src/resources/mdkversion.txt b/src/resources/mdkversion.txt index 24ba9a3..860487c 100644 --- a/src/resources/mdkversion.txt +++ b/src/resources/mdkversion.txt @@ -1 +1 @@ -2.7.0 +2.7.1