mirror of
https://github.com/neovim/neovim.git
synced 2026-09-03 21:00:34 +00:00
Problem:
`parse_ssh_config()` compares tables against a freshly allocated empty
table.
- In `parse_multiple_values()`, the guard which avoids flushing an empty
accumulator never applies. Runs of separators and trailing whitespace
push empty strings into the results, and `is_valid()` does not filter
them. `Host alpha beta ` parses as `{ 'alpha', '', 'beta' }`.
- In `parse_value()`, the condition reduces to `chr == '"' and quoted`.
`quoted` starts false and only that branch sets it, so it can never
become true: quotes are never recognised and are inserted literally,
and the unterminated-quote check is unreachable.
Solution:
Compare `#val` instead. Add a test for repeated and trailing separators.
AI-assisted
92 lines
2.1 KiB
Lua
92 lines
2.1 KiB
Lua
local t = require('test.testutil')
|
|
local parser = require('vim.net._ssh')
|
|
local describe, it = t.describe, t.it
|
|
local eq = t.eq
|
|
|
|
describe('SSH parser', function()
|
|
it('parses SSH configuration strings', function()
|
|
local config = [[
|
|
Host *
|
|
ConnectTimeout 10
|
|
ServerAliveInterval 60
|
|
ServerAliveCountMax 3
|
|
# Use a specific key for any host not otherwise specified
|
|
# IdentityFile ~/.ssh/id_rsa
|
|
|
|
Host=dev
|
|
HostName=dev.example.com
|
|
User=devuser
|
|
Port=2222
|
|
IdentityFile=~/.ssh/id_rsa_dev
|
|
|
|
Host prod test
|
|
HostName 198.51.100.10
|
|
User admin
|
|
Port 22
|
|
IdentityFile ~/.ssh/id_rsa_prod
|
|
ForwardAgent yes
|
|
|
|
Host test
|
|
IdentitiesOnly yes
|
|
|
|
Host "quoted string"
|
|
User quote
|
|
Port 22
|
|
|
|
Match host foo host gh
|
|
HostName github.com
|
|
User git
|
|
IdentityFile ~/.ssh/id_rsa_github
|
|
IdentitiesOnly yes
|
|
]]
|
|
|
|
eq({
|
|
'dev',
|
|
'prod',
|
|
'test',
|
|
'quoted string',
|
|
'gh',
|
|
}, parser.parse_ssh_config(config))
|
|
end)
|
|
|
|
it('ignores repeated and trailing separators', function()
|
|
-- Runs of separators between values, and trailing whitespace before the
|
|
-- line break, must not yield empty hostnames.
|
|
local config = table.concat({
|
|
'Host alpha beta ',
|
|
' HostName example.com',
|
|
'',
|
|
}, '\n')
|
|
|
|
eq({ 'alpha', 'beta' }, parser.parse_ssh_config(config))
|
|
end)
|
|
|
|
it('fails when a quote is not closed', function()
|
|
local config = [[
|
|
Host prod dev "test prod my
|
|
HostName 198.51.100.10
|
|
User admin
|
|
Port 22
|
|
IdentityFile ~/.ssh/id_rsa_prod
|
|
ForwardAgent yes
|
|
]]
|
|
|
|
local ok, _ = pcall(parser.parse_ssh_config, config)
|
|
eq(false, ok)
|
|
end)
|
|
|
|
it('fails when the line ends with a single backslash', function()
|
|
local config = [[
|
|
Host prod test
|
|
HostName 198.51.100.10
|
|
User admin\
|
|
Port 22
|
|
IdentityFile ~/.ssh/id_rsa_prod
|
|
ForwardAgent yes
|
|
]]
|
|
|
|
local ok, _ = pcall(parser.parse_ssh_config, config)
|
|
eq(false, ok)
|
|
end)
|
|
end)
|