speedata / publisher

speedata Publisher - a professional database Publishing system
https://www.speedata.de/
GNU Affero General Public License v3.0
292 stars 36 forks source link

`<AttachFile name="…">`: extension from `filename` #441

Closed pr-apes closed 1 year ago

pr-apes commented 1 year ago

when name is missing the extension

pgundlach commented 1 year ago

Thank you very much for the patch, it will be included in the next version.

I have slightly edited the code since filename is an optional parameter and might be nil. Also added a warning for the user.

 src/lua/publisher/commands.lua | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/lua/publisher/commands.lua b/src/lua/publisher/commands.lua
index d57d2db5..0a146d85 100644
--- a/src/lua/publisher/commands.lua
+++ b/src/lua/publisher/commands.lua
@@ -196,6 +196,11 @@ function commands.attachfile( layoutxml,dataxml )
             return
         end
         local stat = lfs.attributes(path)
+        local filename_extension = filename:match("^.*%.(.+)$"):lower()
+        if destfilename:match("^.*%.(.+)$") == nil then
+            warning("AttachFile: name attribute has no file extension, take from source.")
+            destfilename = string.format("%s.%s",destfilename,filename_extension)
+        end
         modificationtime = stat.modification
         local zugferdfile = io.open(path)
pr-apes commented 1 year ago

Many thanks for the improvements.

I didn't realize that filename could be an optional parameter.