Skip to content

Commit 39e8329

Browse files
Copilotbytemain
andauthored
Clarify unsupported command characters
Agent-Logs-Url: https://github.com/version-fox/vfox-python/sessions/62cb80ef-ebad-4aa5-8791-70cc74b8efc5 Co-authored-by: bytemain <13938334+bytemain@users.noreply.github.com>
1 parent 251e48a commit 39e8329

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

lib/util.lua

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,19 @@ local function containsTraversalSegment(value)
241241
return false
242242
end
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
246253
end
247254

248255
local 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)
265272
end
266273

267274
local 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

Comments
 (0)