aboutsummaryrefslogtreecommitdiff
path: root/test/functional/treesitter/language_spec.lua
diff options
context:
space:
mode:
authorChristian Clason <c.clason@uni-graz.at>2023-01-26 09:42:23 +0100
committerChristian Clason <c.clason@uni-graz.at>2023-01-28 11:28:52 +0100
commitc032e83b22994332dd8769ef34cb817906a63cac (patch)
tree5c2d8c7131e07c1a6597c496d018e60e706e4cda /test/functional/treesitter/language_spec.lua
parentb4c4c232ba6fe3df5c6f12faff4405a16e4d40df (diff)
downloadrneovim-c032e83b22994332dd8769ef34cb817906a63cac.tar.gz
rneovim-c032e83b22994332dd8769ef34cb817906a63cac.tar.bz2
rneovim-c032e83b22994332dd8769ef34cb817906a63cac.zip
fix(treesitter): validate language name
Problem: Some injections (like markdown) allow specifying arbitrary language names for code blocks, which may be lead to errors when looking for a corresponding parser in runtime path. Solution: Validate that the language name only contains alphanumeric characters and `_` (e.g., for `c_sharp`) and error otherwise.
Diffstat (limited to 'test/functional/treesitter/language_spec.lua')
-rw-r--r--test/functional/treesitter/language_spec.lua5
1 files changed, 5 insertions, 0 deletions
diff --git a/test/functional/treesitter/language_spec.lua b/test/functional/treesitter/language_spec.lua
index f95b05a1cc..df45c9b384 100644
--- a/test/functional/treesitter/language_spec.lua
+++ b/test/functional/treesitter/language_spec.lua
@@ -31,6 +31,11 @@ describe('treesitter language API', function()
pcall_err(exec_lua, 'vim.treesitter.require_language("c", nil, false, "borklang")'))
end)
+ it('shows error for invalid language name', function()
+ eq(".../language.lua:0: '/foo/' is not a valid language name",
+ pcall_err(exec_lua, 'vim.treesitter.require_language("/foo/", nil, false)'))
+ end)
+
it('inspects language', function()
local keys, fields, symbols = unpack(exec_lua([[
local lang = vim.treesitter.inspect_language('c')