mirror of
https://github.com/neovim/neovim.git
synced 2025-12-10 08:32:42 +00:00
vim.uri: fix uri_to_fname (#12059)
fix: #12056 If the colon of the drive letter of windows is URI encoded, it doesn't match the expected pattern, so decode it first.
This commit is contained in:
@@ -70,6 +70,7 @@ local function uri_from_bufnr(bufnr)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function uri_to_fname(uri)
|
local function uri_to_fname(uri)
|
||||||
|
uri = uri_decode(uri)
|
||||||
-- TODO improve this.
|
-- TODO improve this.
|
||||||
if is_windows_file_uri(uri) then
|
if is_windows_file_uri(uri) then
|
||||||
uri = uri:gsub('^file:///', '')
|
uri = uri:gsub('^file:///', '')
|
||||||
@@ -77,7 +78,7 @@ local function uri_to_fname(uri)
|
|||||||
else
|
else
|
||||||
uri = uri:gsub('^file://', '')
|
uri = uri:gsub('^file://', '')
|
||||||
end
|
end
|
||||||
return uri_decode(uri)
|
return uri
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Return or create a buffer for a uri.
|
-- Return or create a buffer for a uri.
|
||||||
|
|||||||
@@ -85,6 +85,15 @@ describe('URI methods', function()
|
|||||||
eq('C:\\Foo\\Bar\\Baz.txt', exec_lua(test_case))
|
eq('C:\\Foo\\Bar\\Baz.txt', exec_lua(test_case))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('file path includes only ascii charactors with encoded colon character', function()
|
||||||
|
local test_case = [[
|
||||||
|
local uri = 'file:///C%3A/Foo/Bar/Baz.txt'
|
||||||
|
return vim.uri_to_fname(uri)
|
||||||
|
]]
|
||||||
|
|
||||||
|
eq('C:\\Foo\\Bar\\Baz.txt', exec_lua(test_case))
|
||||||
|
end)
|
||||||
|
|
||||||
it('file path including white space', function()
|
it('file path including white space', function()
|
||||||
local test_case = [[
|
local test_case = [[
|
||||||
local uri = 'file:///C:/Foo%20/Bar/Baz.txt'
|
local uri = 'file:///C:/Foo%20/Bar/Baz.txt'
|
||||||
|
|||||||
Reference in New Issue
Block a user