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:
parent
7274c9de46
commit
0af52a0f6d
1 changed files with 9 additions and 1 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue