Skip to content

Commit b7c8759

Browse files
authored
Merge pull request #523 from koto/sanitize_filename
Properly sanitize filenames in dtutils.file file_copy and file_move. Thanks
2 parents 2953cf7 + d754e37 commit b7c8759

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

lib/dtutils/file.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -519,9 +519,9 @@ function dtutils_file.file_copy(fromFile, toFile)
519519
local result = nil
520520
-- if cp exists, use it
521521
if dt.configuration.running_os == "windows" then
522-
result = os.execute('copy "' .. fromFile .. '" "' .. toFile .. '"')
522+
result = os.execute('copy ' .. dtutils_file.sanitize_filename(fromFile) .. ' ' .. dtutils_file.sanitize_filename(toFile))
523523
elseif dtutils_file.check_if_bin_exists("cp") then
524-
result = os.execute("cp '" .. fromFile .. "' '" .. toFile .. "'")
524+
result = os.execute("cp " .. dtutils_file.sanitize_filename(fromFile) .. ' ' .. dtutils_file.sanitize_filename(toFile))
525525
end
526526

527527
-- if cp was not present, or if cp failed, then a pure lua solution
@@ -572,7 +572,7 @@ function dtutils_file.file_move(fromFile, toFile)
572572
if not success then
573573
-- an error occurred, so let's try using the operating system function
574574
if dtutils_file.check_if_bin_exists("mv") then
575-
success = os.execute("mv '" .. fromFile .. "' '" .. toFile .. "'")
575+
success = os.execute("mv " .. dtutils_file.sanitize_filename(fromFile) .. ' ' .. dtutils_file.sanitize_filename(toFile))
576576
end
577577
-- if the mv didn't exist or succeed, then...
578578
if not success then

0 commit comments

Comments
 (0)