fix: url-escape paths for scp (#134)

This commit is contained in:
Steven Arcangeli 2023-06-30 00:55:38 -07:00
parent 789b486fb5
commit a5ff72a8da
2 changed files with 36 additions and 1 deletions

View file

@ -75,7 +75,8 @@ local function url_to_scp(url)
table.insert(pieces, string.format(":%d", url.port))
end
table.insert(pieces, "/")
table.insert(pieces, url.path)
local escaped_path = util.url_escape(url.path)
table.insert(pieces, escaped_path)
return table.concat(pieces, "")
end

View file

@ -23,6 +23,40 @@ M.escape_filename = function(filename)
return ret
end
local _url_escape_chars = {
[" "] = "%20",
["$"] = "%24",
["&"] = "%26",
["`"] = "%60",
[":"] = "%3A",
["<"] = "%3C",
["="] = "%3D",
[">"] = "%3E",
["?"] = "%3F",
["["] = "%5B",
["\\"] = "%5C",
["]"] = "%5D",
["^"] = "%5E",
["{"] = "%7B",
["|"] = "%7C",
["}"] = "%7D",
["~"] = "%7E",
[""] = "%22",
[""] = "%27",
["+"] = "%2B",
[","] = "%2C",
["#"] = "%23",
["%"] = "%25",
["@"] = "%40",
["/"] = "%2F",
[";"] = "%3B",
}
---@param string string
---@return string
M.url_escape = function(string)
return (string:gsub(".", _url_escape_chars))
end
---@param bufnr integer
---@return nil|oil.Adapter
M.get_adapter = function(bufnr)