fix: url formatting errors when ssh connection specifies port

This commit is contained in:
Steven Arcangeli 2023-01-11 23:23:28 -08:00
parent c553b5435a
commit 9a03af7cb7
2 changed files with 6 additions and 5 deletions

View file

@ -62,16 +62,16 @@ end
---@param url oil.sshUrl ---@param url oil.sshUrl
---@return string ---@return string
local function url_to_scp(url) local function url_to_scp(url)
local pieces = {} local pieces = { "scp://" }
if url.user then if url.user then
table.insert(pieces, url.user) table.insert(pieces, url.user)
table.insert(pieces, "@") table.insert(pieces, "@")
end end
table.insert(pieces, url.host) table.insert(pieces, url.host)
table.insert(pieces, ":")
if url.port then if url.port then
table.insert(pieces, string.format(":%d", url.port)) table.insert(pieces, string.format(":%d", url.port))
end end
table.insert(pieces, "/")
table.insert(pieces, url.path) table.insert(pieces, url.path)
return table.concat(pieces, "") return table.concat(pieces, "")
end end

View file

@ -48,9 +48,6 @@ function SSHConnection.new(url)
if url.user then if url.user then
host = url.user .. "@" .. host host = url.user .. "@" .. host
end end
if url.port then
host = string.format("%s:%d", host, url.port)
end
local command = { local command = {
"ssh", "ssh",
host, host,
@ -61,6 +58,10 @@ function SSHConnection.new(url)
-- anything prior to that, it *will* appear. The first line gets swallowed. -- anything prior to that, it *will* appear. The first line gets swallowed.
"echo '_make_newline_'; echo '===READY==='; exec /bin/bash --norc", "echo '_make_newline_'; echo '===READY==='; exec /bin/bash --norc",
} }
if url.port then
table.insert(command, 2, "-p")
table.insert(command, 3, url.port)
end
local self = setmetatable({ local self = setmetatable({
host = host, host = host,
meta = {}, meta = {},