fix(plugin): fix url based plugin name and added extra safety checks. Fixes #824

This commit is contained in:
Folke Lemaitre 2023-05-25 08:10:08 +02:00
parent 57062f3a09
commit 32170a8891
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
1 changed files with 6 additions and 0 deletions

View File

@ -49,6 +49,7 @@ end
-- PERF: optimized code to get package name without using lua patterns -- PERF: optimized code to get package name without using lua patterns
function Spec.get_name(pkg) function Spec.get_name(pkg)
local name = pkg:sub(-4) == ".git" and pkg:sub(1, -5) or pkg local name = pkg:sub(-4) == ".git" and pkg:sub(1, -5) or pkg
name = name:sub(-1) == "/" and name:sub(1, -2) or name
local slash = name:reverse():find("/", 1, true) --[[@as number?]] local slash = name:reverse():find("/", 1, true) --[[@as number?]]
return slash and name:sub(#name - slash + 2) or pkg:gsub("%W+", "_") return slash and name:sub(#name - slash + 2) or pkg:gsub("%W+", "_")
end end
@ -109,6 +110,11 @@ function Spec:add(plugin, results, is_dep)
return return
end end
if not plugin.name or plugin.name == "" then
self:error("Plugin spec " .. vim.inspect(plugin) .. " has no name")
return
end
if type(plugin.config) == "table" then if type(plugin.config) == "table" then
self:warn( self:warn(
"{" .. plugin.name .. "}: setting a table to `Plugin.config` is deprecated. Please use `Plugin.opts` instead" "{" .. plugin.name .. "}: setting a table to `Plugin.config` is deprecated. Please use `Plugin.opts` instead"