fix(ftp): percent-encode path in curl FTP URLs

Problem: filenames containing spaces (or other URL-unsafe characters)
caused curl to fail with "Unknown error" because the raw path was
concatenated directly into the FTP URL.

Solution: add `url_encode_path` to encode non-safe characters (excluding
`/`) before building the curl URL in `curl_ftp_url`.
This commit is contained in:
Barrett Ruth 2026-03-17 22:38:22 -04:00
parent 7274c9de46
commit 0af52a0f6d
Signed by: barrett
GPG key ID: A6C96C9349D2FC81

View file

@ -75,6 +75,14 @@ local function url_to_str(url)
return table.concat(pieces, '')
end
---@param s string
---@return string
local function url_encode_path(s)
return (s:gsub('[^A-Za-z0-9%-._~:/]', function(c)
return string.format('%%%02X', c:byte())
end))
end
---@param url oil.ftpUrl
---@return string
local function curl_ftp_url(url)
@ -93,7 +101,7 @@ local function curl_ftp_url(url)
table.insert(pieces, string.format(':%d', url.port))
end
table.insert(pieces, '/')
table.insert(pieces, url.path)
table.insert(pieces, url_encode_path(url.path))
return table.concat(pieces, '')
end