add stricter checking on urls and paths, and make sure that if one
package fails to load other may continue to load
This commit is contained in:
@ -55,6 +55,17 @@ local root
|
||||
---@type package[]
|
||||
local packages = {}
|
||||
|
||||
--- check if a string seems to be a url
|
||||
---@param url string the "url" to check
|
||||
---@return boolean is_url
|
||||
local function is_url(url)
|
||||
if url:sub(1, 8) == "https://" or
|
||||
url:sub(1, 7) == "http://" then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
--- check a spec to see if it's correct
|
||||
---@param spec spec|string the specification to check
|
||||
---@return spec|false spec if the spec is ok or false
|
||||
@ -117,6 +128,10 @@ local function check_spec(spec)
|
||||
if type(spec.url) ~= "string" then
|
||||
logger:log("spec", "spec.url must be a string in %s", spec[1])
|
||||
return false
|
||||
elseif not is_url(spec.url) then -- more strict checking on urls
|
||||
logger:log("spec", "spec.url must be a properly formatted url in %s",
|
||||
spec[1])
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
@ -124,6 +139,9 @@ local function check_spec(spec)
|
||||
if type(spec.path) ~= "string" then
|
||||
logger:log("spec", "spec.path must be a string in %s", spec[1])
|
||||
return false
|
||||
elseif not vim.fn.isdirectory(spec.path) then
|
||||
logger:log("spec", "spec.path must be a valid directory in %s", spec[1])
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user