aboutsummaryrefslogtreecommitdiff
path: root/test/functional/treesitter/parser_spec.lua
diff options
context:
space:
mode:
authorLewis Russell <lewis6991@gmail.com>2022-01-27 09:42:59 +0000
committerGitHub <noreply@github.com>2022-01-27 10:42:59 +0100
commitf9080b24c4f60c3772db2b6e713ea5a6a3b52f1e (patch)
treefc288ba0bbecc18b12779ad75d82f831d5de5a7e /test/functional/treesitter/parser_spec.lua
parent2320f705c42cc7d51045b34516264f38abb7ecde (diff)
downloadrneovim-f9080b24c4f60c3772db2b6e713ea5a6a3b52f1e.tar.gz
rneovim-f9080b24c4f60c3772db2b6e713ea5a6a3b52f1e.tar.bz2
rneovim-f9080b24c4f60c3772db2b6e713ea5a6a3b52f1e.zip
fix(ts): escape lang when loading parsers (#16668)
When trying to load a language parser, escape the value of the language. With language injection, the language might be picked up from the buffer. If this value is erroneous it can cause `nvim_get_runtime_file` to hard error. E.g., the markdown expression `~~~{` will extract '{' as a language and then try to get the parser using `parser/{*` as the pattern.
Diffstat (limited to 'test/functional/treesitter/parser_spec.lua')
-rw-r--r--test/functional/treesitter/parser_spec.lua15
1 files changed, 15 insertions, 0 deletions
diff --git a/test/functional/treesitter/parser_spec.lua b/test/functional/treesitter/parser_spec.lua
index 44a7f00d8b..396fe5feab 100644
--- a/test/functional/treesitter/parser_spec.lua
+++ b/test/functional/treesitter/parser_spec.lua
@@ -666,6 +666,21 @@ int x = INT_MAX;
-- READ_STRING_OK(x, y) (char_u *)read_string((x), (size_t)(y))
}, get_ranges())
end)
+
+ it("should not inject bad languages", function()
+ if helpers.pending_win32(pending) then return end
+ exec_lua([=[
+ vim.treesitter.add_directive("inject-bad!", function(match, _, _, pred, metadata)
+ metadata.language = "{"
+ metadata.combined = true
+ metadata.content = pred[2]
+ end)
+
+ parser = vim.treesitter.get_parser(0, "c", {
+ injections = {
+ c = "(preproc_function_def value: ((preproc_arg) @_a (#inject-bad! @_a)))"}})
+ ]=])
+ end)
end)
describe("when using the offset directive", function()