fix(treesitter): validate language alias for injections

Problem: Parsed language annotations can be random garbage so
`nvim_get_runtime_file` throws an error.

Solution: Validate that `alias` is a valid language name before trying
to find a parser for it.
This commit is contained in:
Christian Clason 2024-01-18 15:12:03 +01:00
parent ab3a7fc3e3
commit 674f2513d4

View File

@ -757,6 +757,11 @@ end)
---@param alias string language or filetype name
---@return string? # resolved parser name
local function resolve_lang(alias)
-- validate that `alias` is a legal language
if not (alias and alias:match('[%w_]+') == alias) then
return
end
if has_parser(alias) then
return alias
end