Skip to content

Commit 0872d1f

Browse files
fix(capture): Escape replacement content in capture window
Fixes #701
1 parent 041ff8a commit 0872d1f

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lua/orgmode/capture/template/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ function Template:_compile_expansions(content, found_expansions)
213213
found_expansions = found_expansions or expansions
214214
for expansion, compiler in pairs(found_expansions) do
215215
if content:match(vim.pesc(expansion)) then
216-
content = content:gsub(vim.pesc(expansion), compiler())
216+
content = content:gsub(vim.pesc(expansion), vim.pesc(compiler()))
217217
end
218218
end
219219
return content

tests/plenary/capture/templates_spec.lua

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,21 @@ describe('Capture template', function()
2424
vim.fn.setreg('+', clip_backup)
2525
end)
2626

27+
it('should escape the compiled content', function()
28+
---Backup and restore the clipboard
29+
local clip_backup = vim.fn.getreg('+')
30+
vim.fn.setreg('+', 'nvim-orgmode%20is%20great!')
31+
local template = Template:new({
32+
template = '* TODO [[%x][]]\n',
33+
})
34+
35+
assert.are.same({
36+
'* TODO [[nvim-orgmode%20is%20great!][]]',
37+
'',
38+
}, template:compile())
39+
vim.fn.setreg('+', clip_backup)
40+
end)
41+
2742
it('gets current date for datetree enabled with true', function()
2843
local template = Template:new({
2944
template = '* %?',

0 commit comments

Comments
 (0)