diff --git a/lua/ivy/utils.lua b/lua/ivy/utils.lua index 92f74e0..910e57f 100644 --- a/lua/ivy/utils.lua +++ b/lua/ivy/utils.lua @@ -104,7 +104,8 @@ utils.line_action = function() end utils.escape_file_name = function(input) - return string.gsub(input, "([$])", "\\%1") + local file, _ = string.gsub(input, "([$%]\\[])", "\\%1") + return file end return utils diff --git a/lua/ivy/utils_escape_test.lua b/lua/ivy/utils_escape_test.lua new file mode 100644 index 0000000..ebe41d2 --- /dev/null +++ b/lua/ivy/utils_escape_test.lua @@ -0,0 +1,11 @@ +local utils = require "ivy.utils" + +it("will escape a dollar in the file name", function(t) + local result = utils.escape_file_name "/path/to/$file/$name.lua" + t.assert_equal(result, "/path/to/\\$file/\\$name.lua") +end) + +it("will escape a brackets in the file name", function(t) + local result = utils.escape_file_name "/path/to/[file]/[name].lua" + t.assert_equal(result, "/path/to/\\[file\\]/\\[name\\].lua") +end)