[latex3-commits] [git/LaTeX3-latex3-l3build] spaces: Consistently normalize and escape paths before passing them to the shell (0169ebe)

Marcel Fabian Krüger tex at 2krueger.de
Tue Apr 19 18:49:37 CEST 2022


Repository : https://github.com/latex3/l3build
On branch  : spaces
Link       : https://github.com/latex3/l3build/commit/0169ebe9867687c86bcdd1c69ee8ea325d8d605e

>---------------------------------------------------------------

commit 0169ebe9867687c86bcdd1c69ee8ea325d8d605e
Author: Marcel Fabian Krüger <tex at 2krueger.de>
Date:   Tue Apr 19 18:49:37 2022 +0200

    Consistently normalize and escape paths before passing them to the shell


>---------------------------------------------------------------

0169ebe9867687c86bcdd1c69ee8ea325d8d605e
 l3build-check.lua          | 17 +++++++++++------
 l3build-file-functions.lua | 26 +++++++++++++++-----------
 2 files changed, 26 insertions(+), 17 deletions(-)

diff --git a/l3build-check.lua b/l3build-check.lua
index 7b3191a..726f7e6 100644
--- a/l3build-check.lua
+++ b/l3build-check.lua
@@ -81,7 +81,7 @@ function checkinit()
   for _,i in ipairs(checksuppfiles) do
     cp(i, supportdir, testdir)
   end
-  execute(os_ascii .. ">" .. testdir .. "/ascii.tcx")
+  execute(os_ascii .. ">" .. normalize_and_escape(testdir .. "/ascii.tcx"))
   return checkinit_hook()
 end
 
@@ -678,7 +678,8 @@ function base_compare(test_type,name,engine,cleanup)
     return compare(difffile, reffile, genfile, cleanup, name, engine)
   end
   local errorlevel = execute(os_diffexe .. " "
-    .. normalize_path(reffile .. " " .. genfile .. " > " .. difffile))
+    .. normalize_and_escape(reffile) .. " " .. normalize_and_escape(genfile)
+    .. " > " .. normalize_and_escape(difffile))
   if errorlevel == 0 or cleanup then
     remove(difffile)
   end
@@ -701,15 +702,19 @@ function compare_tlg(difffile, tlgfile, logfile, cleanup, name, engine)
     local luatlgfile = testdir .. "/" .. testname .. tlgext
     rewrite(tlgfile,luatlgfile,normalize_lua_log)
     rewrite(logfile,lualogfile,normalize_lua_log,true)
-    errorlevel = execute(os_diffexe .. " "
-      .. normalize_path(luatlgfile .. " " .. lualogfile .. " > " .. difffile))
+    errorlevel = execute(os_diffexe
+      .. " " .. normalize_and_escape(luatlgfile)
+      .. " " .. normalize_and_escape(lualogfile)
+      .. " > " .. normalize_and_escape(difffile))
     if cleanup then
       remove(lualogfile)
       remove(luatlgfile)
     end
   else
-    errorlevel = execute(os_diffexe .. " "
-      .. normalize_path(tlgfile .. " " .. logfile .. " > " .. difffile))
+    errorlevel = execute(os_diffexe
+      .. " " .. normalize_and_escape(tlgfile)
+      .. " " .. normalize_and_escape(logfile)
+      .. " > " .. normalize_and_escape(difffile))
   end
   if errorlevel == 0 or cleanup then
     remove(difffile)
diff --git a/l3build-file-functions.lua b/l3build-file-functions.lua
index 17f0bd8..822ec43 100644
--- a/l3build-file-functions.lua
+++ b/l3build-file-functions.lua
@@ -202,6 +202,10 @@ function escapepath(path)
   end
 end
 
+function normalize_and_escape(path)
+  return escapepath(normalize_path(path))
+end
+
 -- For cleaning out a directory, which also ensures that it exists
 function cleandir(dir)
   local errorlevel = mkdir(dir)
@@ -234,13 +238,13 @@ function cp(glob, source, dest)
     if os_type == "windows" then
       if direxists(p.cwd) then
         errorlevel = execute(
-          'xcopy /y /e /i "' .. unix_to_win(p.cwd) .. '" '
-             .. unix_to_win(dest .. '/' .. escapepath(p.src)) .. ' > nul'
+          'xcopy /y /e /i ' .. normalize_and_escape(p.cwd) .. ' '
+             .. normalize_and_escape(dest .. '/' .. p.src) .. ' > nul'
         ) and 0 or 1
       else
         errorlevel = execute(
-          'xcopy /y "' .. unix_to_win(p.cwd) .. '" '
-             .. unix_to_win(dest .. '/') .. ' > nul'
+          'xcopy /y ' .. normalize_and_escape(p.cwd) .. ' '
+             .. normalize_and_escape(dest .. '/') .. ' > nul'
         ) and 0 or 1
       end
     else
@@ -250,7 +254,7 @@ function cp(glob, source, dest)
         if errorlevel ~=0 then return errorlevel end
       end
       errorlevel = execute(
-        "cp -RLf '" .. p.cwd .. "' " .. dest
+        "cp -RLf " .. normalize_and_escape(p.cwd) .. " " .. normalize_and_escape(dest)
       ) and 0 or 1
     end
     if errorlevel ~=0 then
@@ -372,7 +376,7 @@ function remove_duplicates(a)
 end
 
 function mkdir(dir)
-  dir = escapepath(dir)
+  dir = normlaize_and_escape(dir)
   if os_type == "windows" then
     -- Windows (with the extensions) will automatically make directory trees
     -- but issues a warning if the dir already exists: avoid by including a test
@@ -391,9 +395,9 @@ function ren(dir, source, dest)
   if os_type == "windows" then
     source = gsub(source, "^%.+/", "")
     dest = gsub(dest, "^%.+/", "")
-    return execute("ren " .. unix_to_win(dir) .. source .. " " .. dest)
+    return execute("ren " .. normalize_and_escape(dir .. source) .. ' ' .. normalize_and_escape(dest))
   else
-    return execute("mv " .. dir .. source .. " " .. dir .. dest)
+    return execute("mv " .. normalize_and_escape(dir .. source) .. ' ' .. normalize_and_escape(dir .. dest))
   end
 end
 
@@ -418,15 +422,15 @@ function rmdir(dir)
   -- First, make sure it exists to avoid any errors
   mkdir(dir)
   if os_type == "windows" then
-    return execute("rmdir /s /q " .. unix_to_win(dir))
+    return execute("rmdir /s /q " .. normalize_and_escape(dir))
   else
-    return execute("rm -r " .. dir)
+    return execute("rm -r " .. normalize_and_escape(dir))
   end
 end
 
 -- Run a command in a given directory
 function run(dir, cmd)
-  return execute("cd " .. dir .. os_concat .. cmd)
+  return execute("cd " .. normalize_and_escape(dir) .. os_concat .. cmd)
 end
 
 -- Split a path into file and directory component





More information about the latex3-commits mailing list.