From c9e490e042fd99b5a4c480029ab2680f80bc5bf0 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Fri, 21 Jan 2022 17:13:44 +0100 Subject: [PATCH] Escape file name for file to edit Use `fnameescape` before trying to edit a file when you open it through a link. --- lua/test/action_spec.lua | 7 ++++++- lua/zettelkasten/action.lua | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lua/test/action_spec.lua b/lua/test/action_spec.lua index d720f4c..240f27d 100644 --- a/lua/test/action_spec.lua +++ b/lua/test/action_spec.lua @@ -1,7 +1,12 @@ local action = require 'zettelkasten.action' before_each(function() - _G.vim = {g = {}, b = {}, loop = {fs_scandir = function() end}} + _G.vim = { + g = {}, + b = {}, + fn = {fnameescape = function(input) return input end}, + loop = {fs_scandir = function() end} + } end) after_each(function() _G.vim = nil end) diff --git a/lua/zettelkasten/action.lua b/lua/zettelkasten/action.lua index 2eff445..86868a1 100644 --- a/lua/zettelkasten/action.lua +++ b/lua/zettelkasten/action.lua @@ -11,7 +11,7 @@ function A.open(link) if not link or not link.ref then return end local fname = f.get_zettel_by_anchor(link.anchor) or f.get_zettel_by_ref(link.ref) or link.ref - vim.api.nvim_command(string.format("edit %s", fname)) + vim.api.nvim_command(string.format("edit %s", vim.fn.fnameescape(fname))) end -- Gets the input at the current buffer cursor and opens it