aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/treesitter/languagetree.lua
diff options
context:
space:
mode:
authorChristian Clason <c.clason@uni-graz.at>2024-01-18 15:12:03 +0100
committerChristian Clason <c.clason@uni-graz.at>2024-01-18 15:46:08 +0100
commit674f2513d4d43688a55913456e6c01ddacceb199 (patch)
treed808f180a691af230fcaeed2f87af8a244c9d57c /runtime/lua/vim/treesitter/languagetree.lua
parentab3a7fc3e3c0166f5792526699f035dd9e057ee9 (diff)
downloadrneovim-674f2513d4d43688a55913456e6c01ddacceb199.tar.gz
rneovim-674f2513d4d43688a55913456e6c01ddacceb199.tar.bz2
rneovim-674f2513d4d43688a55913456e6c01ddacceb199.zip
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.
Diffstat (limited to 'runtime/lua/vim/treesitter/languagetree.lua')
-rw-r--r--runtime/lua/vim/treesitter/languagetree.lua5
1 files changed, 5 insertions, 0 deletions
diff --git a/runtime/lua/vim/treesitter/languagetree.lua b/runtime/lua/vim/treesitter/languagetree.lua
index a249a10f47..971c4449e8 100644
--- a/runtime/lua/vim/treesitter/languagetree.lua
+++ b/runtime/lua/vim/treesitter/languagetree.lua
@@ -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