@@ -259,14 +259,32 @@ local function shellQuote(value)
259259 return " '" .. string.gsub (value , " '" , " '\\ ''" ) .. " '"
260260end
261261
262- local function powerShellCommand (script , args )
263- local command = " powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command " .. shellQuote (script )
264- for _ , arg in ipairs (args ) do
265- command = command .. " " .. shellQuote (arg )
262+ local function powerShellQuote (value )
263+ if string.find (value , " [\r\n %z]" ) then
264+ error (" PowerShell argument contains unsupported control character: " .. value )
265+ end
266+ if containsTraversalSegment (value ) then
267+ error (" PowerShell argument contains unsupported traversal segment: " .. value )
268+ end
269+ if string.find (value , ' "' , 1 , true ) then
270+ error (" PowerShell argument contains unsupported quote character: " .. value )
266271 end
272+ return " '" .. string.gsub (value , " '" , " ''" ) .. " '"
273+ end
274+
275+ local function powerShellCommand (script )
276+ local command = " powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command " .. shellQuote (script )
267277 return command
268278end
269279
280+ local function powerShellPythonCommand (pythonExe , pythonArgs )
281+ local script = " & " .. powerShellQuote (pythonExe )
282+ for _ , arg in ipairs (pythonArgs ) do
283+ script = script .. " " .. powerShellQuote (arg )
284+ end
285+ return powerShellCommand (script )
286+ end
287+
270288local function startsWith (value , prefix )
271289 return string.sub (value , 1 , string.len (prefix )) == prefix
272290end
@@ -556,7 +574,7 @@ local function ensureWindowsUvBuildPip(path)
556574 end
557575
558576 print (" Installing pip for uv-build Python on Windows..." )
559- local command = powerShellCommand ( " & { & $args[0] -E -s -m ensurepip -U --default-pip } " , { pythonExe })
577+ local command = powerShellPythonCommand ( pythonExe , { " -E " , " -s " , " -m " , " ensurepip" , " -U " , " --default-pip" })
560578 local exitCode = os.execute (command )
561579 if not commandSucceeded (exitCode ) then
562580 error (" ensurepip failed while installing pip. Exit code: " .. tostring (exitCode ))
@@ -566,8 +584,10 @@ local function ensureWindowsUvBuildPip(path)
566584 return
567585 end
568586
569- command = powerShellCommand (" & { & $args[0] -E -s -m pip install --force-reinstall --no-index --find-links $args[1] pip }" ,
570- { pythonExe , path .. " \\ Lib\\ ensurepip\\ _bundled" })
587+ command = powerShellPythonCommand (pythonExe , {
588+ " -E" , " -s" , " -m" , " pip" , " install" , " --force-reinstall" , " --no-index" ,
589+ " --find-links" , path .. " \\ Lib\\ ensurepip\\ _bundled" , " pip"
590+ })
571591 exitCode = os.execute (command )
572592 if not commandSucceeded (exitCode ) then
573593 error (" pip force-reinstall failed while creating pip scripts. Exit code: " .. tostring (exitCode ))
0 commit comments