From 0af52a0f6dd88682fea4297eedb5b3c3ba640a2f Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Tue, 17 Mar 2026 22:38:22 -0400 Subject: [PATCH] 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`. --- lua/oil/adapters/ftp.lua | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lua/oil/adapters/ftp.lua b/lua/oil/adapters/ftp.lua index a09fbdb..db7eea2 100644 --- a/lua/oil/adapters/ftp.lua +++ b/lua/oil/adapters/ftp.lua @@ -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