feat(vim.uri): Allow URI schemes other than file: without authority

This commit is contained in:
Tom Payne 2021-07-02 15:27:04 +01:00 committed by Alessandro Pezzoni
parent 82a443e1f3
commit 1dab9357de
2 changed files with 16 additions and 1 deletions

View File

@ -74,7 +74,7 @@ local function uri_from_fname(path)
return table.concat(uri_parts)
end
local URI_SCHEME_PATTERN = '^([a-zA-Z]+[a-zA-Z0-9+-.]*):/+.*'
local URI_SCHEME_PATTERN = '^([a-zA-Z]+[a-zA-Z0-9+-.]*):.*'
--- Get a URI from a bufnr
--@param bufnr (number): Buffer number

View File

@ -140,6 +140,12 @@ describe('URI methods', function()
return vim.uri_to_fname('JDT://content/%5C/')
]])
end)
it('uri_to_fname returns non-file scheme URI without authority unchanged', function()
eq('zipfile:/path/to/archive.zip%3A%3Afilename.txt', exec_lua [[
return vim.uri_to_fname('zipfile:/path/to/archive.zip%3A%3Afilename.txt')
]])
end)
end)
describe('decode URI without scheme', function()
@ -161,5 +167,14 @@ describe('URI methods', function()
]], uri)
eq(uri, exec_lua(test_case))
end)
it('uri_to_bufnr & uri_from_bufnr returns original uri for non-file uris without authority', function()
local uri = 'zipfile:/path/to/archive.zip%3A%3Afilename.txt'
local test_case = string.format([[
local uri = '%s'
return vim.uri_from_bufnr(vim.uri_to_bufnr(uri))
]], uri)
eq(uri, exec_lua(test_case))
end)
end)
end)