mirror of
https://github.com/neovim/neovim.git
synced 2024-12-19 18:55:14 -07:00
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:
parent
ab3a7fc3e3
commit
674f2513d4
@ -757,6 +757,11 @@ end)
|
|||||||
---@param alias string language or filetype name
|
---@param alias string language or filetype name
|
||||||
---@return string? # resolved parser name
|
---@return string? # resolved parser name
|
||||||
local function resolve_lang(alias)
|
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
|
if has_parser(alias) then
|
||||||
return alias
|
return alias
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user