commit 265bfde: Change comment to asserts. String type check before tostring call
Jason Stephenson
j.stephenson at live.co.uk
Mon Jul 25 16:21:09 UTC 2022
Author: Jason Stephenson
Date: 2022-07-24 19:28:11 +0100
URL: https://github.com/rspamd/rspamd/commit/265bfde0a3088b23f6e7b7476fd4cf02dd4ea8be
Change comment to asserts. String type check before tostring call
---
lualib/rspamadm/mime.lua | 35 ++++++++++++++++++++++++-----------
1 file changed, 24 insertions(+), 11 deletions(-)
diff --git a/lualib/rspamadm/mime.lua b/lualib/rspamadm/mime.lua
index 782524545..2bff5f07c 100644
--- a/lualib/rspamadm/mime.lua
+++ b/lualib/rspamadm/mime.lua
@@ -880,15 +880,6 @@ local function sign_handler(opts)
end
-- Strips directories and .extensions (if present) from a filepath
- -- very_simple
- -- /home/very_simple.eml
- -- very_simple.eml
- -- very_simple.example.eml
- -- /home/very_simple
- -- home/very_simple
- -- ./home/very_simple
- -- ../home/very_simple.eml
---All the above end up as very_simple
local function filename_only(filepath)
local filename = filepath:match(".*%/([^%.]+)")
if not filename then
@@ -897,6 +888,16 @@ local function filename_only(filepath)
return filename
end
+assert(filename_only("very_simple") == "very_simple")
+assert(filename_only("/home/very_simple.eml") == "very_simple")
+assert(filename_only("very_simple.eml") == "very_simple")
+assert(filename_only("very_simple.example.eml") == "very_simple")
+assert(filename_only("/home/very_simple") == "very_simple")
+assert(filename_only("home/very_simple") == "very_simple")
+assert(filename_only("./home/very_simple") == "very_simple")
+assert(filename_only("../home/very_simple.eml") == "very_simple")
+assert(filename_only("/home/dir.with.dots/very_simple.eml") == "very_simple")
+
--Write the dump content to file or standard out
local function write_dump_content(dump_content, fname, extension, outdir)
local wrote_filepath = nil
@@ -931,7 +932,12 @@ local function get_dump_content(task, opts, fname)
for i, part in ipairs(ucl_object.parts) do
if part.content then
local part_filename = string.format("%s-part%d", filename_only(fname), i)
- local part_path = write_dump_content(tostring(part.content), part_filename, "raw", opts.outdir)
+ local part_path = nil
+ if type(part.content) == "string" then
+ part_path = write_dump_content(part.content, part_filename, "raw", opts.outdir)
+ else
+ part_path = write_dump_content(tostring(part.content), part_filename, "raw", opts.outdir)
+ end
if part_path then
part.content = ucl.null
part.content_path = part_path
@@ -943,7 +949,14 @@ local function get_dump_content(task, opts, fname)
local extension = output_fmt(opts)
return ucl.to_format(ucl_object, extension), extension
end
- return tostring(task:get_content()), "mime"
+
+ local content = task:get_content()
+ if type(content) == "string" then
+ return content, "mime"
+ else
+ return tostring(content), "mime"
+ end
+
end
local function dump_handler(opts)
More information about the Commits
mailing list