fix(vim.opt): Fix #14668 Now correctly handles unescaped commas in isfname style

This commit is contained in:
TJ DeVries 2021-06-11 13:39:59 -04:00
parent 9119ea1bec
commit 6ecec87c09
3 changed files with 59 additions and 2 deletions

View File

@ -405,12 +405,46 @@ local convert_value_to_lua = (function()
[OptionTypes.NUMBER] = function(_, value) return value end,
[OptionTypes.STRING] = function(_, value) return value end,
[OptionTypes.ARRAY] = function(_, value)
[OptionTypes.ARRAY] = function(info, value)
if type(value) == "table" then
value = remove_duplicate_values(value)
if not info.allows_duplicates then
value = remove_duplicate_values(value)
end
return value
end
-- Handles unescaped commas in a list.
if string.find(value, ",,,") then
local comma_split = vim.split(value, ",,,")
local left = comma_split[1]
local right = comma_split[2]
local result = {}
vim.list_extend(result, vim.split(left, ","))
table.insert(result, ",")
vim.list_extend(result, vim.split(right, ","))
table.sort(result)
return result
end
if string.find(value, ",^,,", 1, true) then
local comma_split = vim.split(value, ",^,,", true)
local left = comma_split[1]
local right = comma_split[2]
local result = {}
vim.list_extend(result, vim.split(left, ","))
table.insert(result, "^,")
vim.list_extend(result, vim.split(right, ","))
table.sort(result)
return result
end
return vim.split(value, ",")
end,

View File

@ -2003,6 +2003,7 @@ describe('API', function()
it('should have information about window options', function()
eq({
allows_duplicates = true,
commalist = false;
default = "";
flaglist = false;
@ -2020,6 +2021,7 @@ describe('API', function()
it('should have information about buffer options', function()
eq({
allows_duplicates = true,
commalist = false,
default = "",
flaglist = false,
@ -2041,6 +2043,7 @@ describe('API', function()
eq(false, meths.get_option'showcmd')
eq({
allows_duplicates = true,
commalist = false,
default = true,
flaglist = false,

View File

@ -1731,6 +1731,26 @@ describe('lua stdlib', function()
]]))
end)
end)
-- isfname=a,b,c,,,d,e,f
it('can handle isfname ,,,', function()
local result = exec_lua [[
vim.opt.isfname = "a,b,,,c"
return { vim.opt.isfname:get(), vim.api.nvim_get_option('isfname') }
]]
eq({{",", "a", "b", "c"}, "a,b,,,c"}, result)
end)
-- isfname=a,b,c,^,,def
it('can handle isfname ,^,,', function()
local result = exec_lua [[
vim.opt.isfname = "a,b,^,,c"
return { vim.opt.isfname:get(), vim.api.nvim_get_option('isfname') }
]]
eq({{"^,", "a", "b", "c"}, "a,b,^,,c"}, result)
end)
end) -- vim.opt
it('vim.cmd', function()