diff options
author | Mathias Fußenegger <mfussenegger@users.noreply.github.com> | 2020-05-21 18:17:21 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-22 01:17:21 +0900 |
commit | 04a0486c66e2ae6d67cad990f95283863dbe28fd (patch) | |
tree | c65d01889914915238c5848ffaaa19c5841a0e23 /runtime/lua/vim | |
parent | 044eb56ed2f44b545e7488990ecf195a930174aa (diff) | |
download | rneovim-04a0486c66e2ae6d67cad990f95283863dbe28fd.tar.gz rneovim-04a0486c66e2ae6d67cad990f95283863dbe28fd.tar.bz2 rneovim-04a0486c66e2ae6d67cad990f95283863dbe28fd.zip |
Change uri_to_fname to not convert non-file URIs (#12351)
* Change uri_to_fname to not convert non-file URIs
A URI with a scheme other than file doesn't have a local file path.
* fixup! Change uri_to_fname to not convert non-file URIs
* fixup! fixup! Change uri_to_fname to not convert non-file URIs
Diffstat (limited to 'runtime/lua/vim')
-rw-r--r-- | runtime/lua/vim/uri.lua | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/runtime/lua/vim/uri.lua b/runtime/lua/vim/uri.lua index e28cc9e20f..9c3535c676 100644 --- a/runtime/lua/vim/uri.lua +++ b/runtime/lua/vim/uri.lua @@ -65,9 +65,11 @@ local function uri_from_fname(path) return table.concat(uri_parts) end +local URI_SCHEME_PATTERN = '^([a-zA-Z]+[a-zA-Z0-9+-.]*)://.*' + local function uri_from_bufnr(bufnr) local fname = vim.api.nvim_buf_get_name(bufnr) - local scheme = fname:match("^([a-z]+)://.*") + local scheme = fname:match(URI_SCHEME_PATTERN) if scheme then return fname else @@ -76,6 +78,10 @@ local function uri_from_bufnr(bufnr) end local function uri_to_fname(uri) + local scheme = assert(uri:match(URI_SCHEME_PATTERN), 'URI must contain a scheme: ' .. uri) + if scheme ~= 'file' then + return uri + end uri = uri_decode(uri) -- TODO improve this. if is_windows_file_uri(uri) then @@ -89,7 +95,7 @@ end -- Return or create a buffer for a uri. local function uri_to_bufnr(uri) - local scheme = assert(uri:match("^([a-z]+)://.*"), 'Uri must contain a scheme: ' .. uri) + local scheme = assert(uri:match(URI_SCHEME_PATTERN), 'URI must contain a scheme: ' .. uri) if scheme == 'file' then return vim.fn.bufadd(uri_to_fname(uri)) else |