Skip to content

Commit

Permalink
fix(#820): Illegal character in filename (#1147)
Browse files Browse the repository at this point in the history
* fix(#820): handle % in path

* fix merge issues

---------

merged alongside f76d9b6

Co-authored-by: Shadman <[email protected]>
  • Loading branch information
joaomsa and shadmansaleh authored Dec 26, 2023
1 parent 3abbbdd commit 566b703
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lua/lualine/components/filename.lua
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ M.update_status = function(self)
data = shorten_path(data, path_separator, estimated_space_available)
end

data = modules.utils.stl_escape(data)

local symbols = {}
if self.options.file_status then
if vim.bo.modified then
Expand All @@ -111,8 +113,6 @@ M.update_status = function(self)
table.insert(symbols, self.options.symbols.newfile)
end

data = modules.utils.stl_escape(data)

return data .. (#symbols > 0 and ' ' .. table.concat(symbols, '') or '')
end

Expand Down
21 changes: 21 additions & 0 deletions tests/spec/component_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,27 @@ describe('Filename component', function()
vim.fn.winwidth:revert()
vim.fn.expand:revert()
end)

it('shortens path with %', function()
stub(vim.fn, 'expand')
vim.fn.expand.on_call_with('%:p').returns('%dir1/%dir2/%actual_%file')
stub(vim.fn, 'winwidth')
vim.fn.winwidth.on_call_with(0).returns(100)

local opts = build_component_opts {
component_separators = { left = '', right = '' },
padding = 0,
file_status = false,
path = 2,
shorting_target = 90,
}
vim.cmd(':e test-file.txt')
assert_component('filename', opts, '%%/%%/%%actual_%%file')

vim.cmd(':bdelete!')
vim.fn.winwidth:revert()
vim.fn.expand:revert()
end)
end)

describe('vim option & variable component', function()
Expand Down

0 comments on commit 566b703

Please sign in to comment.