fix: opening file with square brackets in them

Summary:

Fixes an issue where you could not open files that were already open with ivy.
If the file path contains a square brackets and that file is already loaded
into a buffer, ivy will throw an error when trying to open it via "files" or
"buffers".

This is an issue with the file escaping before we try and cal `buffer` passing
in the file path to go to the buffer rather than open a new buffer.

This is common with JS frameworks like next js for parameters in file based
routing.

Test Plan:

Test have been added for this change. I have also added tests for the dollar
that was previously handled.
This commit is contained in:
Ade Attwood 2024-02-13 09:19:05 +00:00
parent 6dd5323380
commit cf3e7e3044
2 changed files with 13 additions and 1 deletions

View file

@ -104,7 +104,8 @@ utils.line_action = function()
end end
utils.escape_file_name = function(input) utils.escape_file_name = function(input)
return string.gsub(input, "([$])", "\\%1") local file, _ = string.gsub(input, "([$%]\\[])", "\\%1")
return file
end end
return utils return utils

View file

@ -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)