mirror of
https://github.com/neovim/neovim.git
synced 2026-08-27 01:21:48 +00:00
refactor(zip)!: address entries with zip:// paths
Problem:
`zipfile://{archive}::{entry}` is ambiguous: `::` is legal in both an
archive path and an entry path, so the separator cannot be identified.
Splitting at the last `::` reads archives correctly but breaks entries
that contain it, and the plugin then emits buffer names it cannot read
back.
Solution:
Address entries as `zip://{archive}/{entry}`, joining the two paths.
Resolve the split by walking components: the first one that is a regular
file is the archive, because a regular file cannot have children on disk.
Entry paths may then contain any character, and no escaping is needed.
zipPlugin.vim keeps its own scheme, so the Java ftplugin emits whichever
form matches the active plugin until the legacy package is removed.
This commit is contained in:
@@ -196,7 +196,7 @@ describe('nvim.zip', function()
|
||||
it('opens entries at quickfix locations', function()
|
||||
local archive = stage(fixtures, 'browser.zip')
|
||||
clear_zip()
|
||||
local uri = ('zipfile://%s::crlf.txt'):format(archive)
|
||||
local uri = ('zip://%s/crlf.txt'):format(archive)
|
||||
fn.setqflist({}, 'r', { items = { { filename = uri, lnum = 2, col = 1 } } })
|
||||
|
||||
api.nvim_cmd({ cmd = 'cfirst' }, {})
|
||||
@@ -220,12 +220,12 @@ describe('nvim.zip', function()
|
||||
local archive = stage(fixtures, 'browser.zip')
|
||||
clear_zip()
|
||||
|
||||
edit(('zipfile://%s::crlf.txt'):format(archive))
|
||||
edit(('zip://%s/crlf.txt'):format(archive))
|
||||
eq({ 'one', 'two' }, lines())
|
||||
eq('dos', api.nvim_get_option_value('fileformat', { buf = 0 }))
|
||||
eq(true, api.nvim_get_option_value('endofline', { buf = 0 }))
|
||||
|
||||
edit(('zipfile://%s::noeol.txt'):format(archive))
|
||||
edit(('zip://%s/noeol.txt'):format(archive))
|
||||
eq({ 'no final newline' }, lines())
|
||||
eq(false, api.nvim_get_option_value('endofline', { buf = 0 }))
|
||||
end)
|
||||
@@ -300,7 +300,9 @@ describe('nvim.zip', function()
|
||||
feed('gf')
|
||||
poke_eventloop()
|
||||
|
||||
eq(('zipfile://%s::folder/root.java'):format(archive), api.nvim_buf_get_name(0))
|
||||
local uri = legacy and ('zipfile://%s::folder/root.java'):format(archive)
|
||||
or ('zip://%s/folder/root.java'):format(archive)
|
||||
eq(uri, api.nvim_buf_get_name(0))
|
||||
eq({ 'class root {}' }, lines())
|
||||
eq('java', api.nvim_get_option_value('filetype', { buf = 0 }))
|
||||
end
|
||||
@@ -323,7 +325,7 @@ describe('nvim.zip', function()
|
||||
{ [[zipglob/a\\.txt]], [[a test file with a double \]] },
|
||||
}
|
||||
for _, case in ipairs(cases) do
|
||||
edit(('zipfile://%s::%s'):format(archive, case[1]))
|
||||
edit(('zip://%s/%s'):format(archive, case[1]))
|
||||
eq({ case[2] }, lines())
|
||||
end
|
||||
end)
|
||||
@@ -335,7 +337,7 @@ describe('nvim.zip', function()
|
||||
edit(archive)
|
||||
eq({ '-d/', 'pwned' }, lines())
|
||||
|
||||
edit(('zipfile://%s::-d/tmp'):format(archive))
|
||||
edit(('zip://%s/-d/tmp'):format(archive))
|
||||
eq({ '' }, lines())
|
||||
end)
|
||||
|
||||
@@ -354,7 +356,7 @@ describe('nvim.zip', function()
|
||||
poke_eventloop()
|
||||
eq({ 'nested payload' }, lines())
|
||||
|
||||
local uri = ('zipfile://%s::crlf.txt'):format(archive)
|
||||
local uri = ('zip://%s/crlf.txt'):format(archive)
|
||||
edit(uri)
|
||||
eq(uri, api.nvim_buf_get_name(0))
|
||||
eq({ 'one', 'two' }, lines())
|
||||
@@ -397,11 +399,11 @@ describe('nvim.zip', function()
|
||||
api.nvim_win_set_cursor(0, { line_of('star*.txt'), 0 })
|
||||
feed('<CR>')
|
||||
poke_eventloop()
|
||||
eq(('zipfile://%s::names/star*.txt'):format(archive), api.nvim_buf_get_name(0))
|
||||
eq(('zip://%s/names/star*.txt'):format(archive), api.nvim_buf_get_name(0))
|
||||
eq({ 'content of star*.txt' }, lines())
|
||||
|
||||
for _, name in ipairs(names) do
|
||||
edit(('zipfile://%s::names/%s'):format(archive, name))
|
||||
edit(('zip://%s/names/%s'):format(archive, name))
|
||||
eq({ 'content of ' .. name }, lines())
|
||||
end
|
||||
end)
|
||||
@@ -418,7 +420,7 @@ describe('nvim.zip', function()
|
||||
exec_lua(function(uri)
|
||||
vim.api.nvim_input('hunter2<CR>')
|
||||
vim.api.nvim_cmd({ cmd = 'edit', args = { uri }, magic = { file = false, bar = false } }, {})
|
||||
end, ('zipfile://%s::secret.txt'):format(archive))
|
||||
end, ('zip://%s/secret.txt'):format(archive))
|
||||
poke_eventloop()
|
||||
|
||||
eq({ 'secret content' }, lines())
|
||||
@@ -432,7 +434,7 @@ describe('nvim.zip', function()
|
||||
exec_lua(function(uri)
|
||||
vim.api.nvim_input('no1<CR>no2<CR>no3<CR>')
|
||||
vim.api.nvim_cmd({ cmd = 'edit', args = { uri }, magic = { file = false, bar = false } }, {})
|
||||
end, ('zipfile://%s::secret.txt'):format(archive))
|
||||
end, ('zip://%s/secret.txt'):format(archive))
|
||||
poke_eventloop()
|
||||
|
||||
eq(true, exec_capture('messages'):find('incorrect password', 1, true) ~= nil)
|
||||
|
||||
Reference in New Issue
Block a user