mirror of
https://github.com/neovim/neovim.git
synced 2026-09-03 21:00:34 +00:00
fix(ssh): compare table length in the SSH config #41637
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
This commit is contained in:
committed by
GitHub
parent
51eacf284c
commit
73923b0dd8
@@ -49,6 +49,18 @@ describe('SSH parser', function()
|
||||
}, 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
|
||||
|
||||
Reference in New Issue
Block a user