Skip to content

Commit

Permalink
Prevent forbidden characters from sneaking into filenames (#40)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
demonnic authored Oct 2, 2022
1 parent 09142e4 commit adbb23f
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion mfile
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
6 changes: 3 additions & 3 deletions src/resources/emco.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/resources/loggingconsole.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/resources/mdkversion.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.7.0
2.7.1

0 comments on commit adbb23f

Please sign in to comment.