Skip to content

Commit 230ccf8

Browse files
authored
fix(snippets): ensure proper espcaping of special chars (#2239)
Previously, when working with the built-in snippet engine, placeholders like `TM_*` or `CLIPBOARD` were populated blindly without escaping special characters. This caused parsing failures, especially for LaTeX snippets with extensive use of these chars. This change ensures proper escaping according to LSP snippet grammar EBNF conventions. Closes #2072 Related #2028
1 parent 2408f14 commit 230ccf8

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

lua/blink/cmp/sources/snippets/default/registry.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,11 @@ function registry:expand_vars(snippet, cache_key)
178178
end
179179

180180
if replacement then
181+
-- Escape special chars according to the snippet grammar EBNF conventions
182+
replacement = replacement:gsub('\\', '\\\\') -- Escape backslashes first!
183+
replacement = replacement:gsub('%$', '\\$')
184+
replacement = replacement:gsub('}', '\\}')
185+
181186
-- Escape % characters (otherwise fails with strings like `%20`)
182187
local escaped = replacement:gsub('%%', '%%%%')
183188

0 commit comments

Comments
 (0)