@@ -241,12 +241,19 @@ local function containsTraversalSegment(value)
241241 return false
242242end
243243
244- local function findControlCharacter (value )
245- return string.find (value , " %c" )
244+ local function findUnsupportedControlCharacter (value )
245+ local controlCharStart = nil
246+ for _ , char in ipairs ({ " \r " , " \n " , string.char (0 ) }) do
247+ local position = string.find (value , char , 1 , true )
248+ if position and (controlCharStart == nil or position < controlCharStart ) then
249+ controlCharStart = position
250+ end
251+ end
252+ return controlCharStart
246253end
247254
248255local function shellQuote (value )
249- local controlCharStart = findControlCharacter (value )
256+ local controlCharStart = findUnsupportedControlCharacter (value )
250257 if controlCharStart then
251258 error (" Path contains unsupported control character at position " .. controlCharStart )
252259 end
@@ -265,7 +272,7 @@ local function shellQuote(value)
265272end
266273
267274local function powerShellQuote (value )
268- local controlCharStart = findControlCharacter (value )
275+ local controlCharStart = findUnsupportedControlCharacter (value )
269276 if controlCharStart then
270277 error (" PowerShell argument contains unsupported control character at position " .. controlCharStart )
271278 end
@@ -274,7 +281,7 @@ local function powerShellQuote(value)
274281 end
275282 -- The generated script is passed to powershell through cmd as a double-quoted -Command argument.
276283 if string.find (value , ' "' , 1 , true ) then
277- error (" PowerShell argument contains unsupported quote character : " .. value )
284+ error (" PowerShell argument contains double quote which conflicts with -Command wrapper : " .. value )
278285 end
279286 -- PowerShell single-quoted strings escape embedded single quotes by doubling them.
280287 return " '" .. string.gsub (value , " '" , " ''" ) .. " '"
0 commit comments