aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/loader.lua
diff options
context:
space:
mode:
authorTyler Miller <tmillr@proton.me>2023-08-01 08:28:28 -0700
committerGitHub <noreply@github.com>2023-08-01 08:28:28 -0700
commit0804034c07ad5883bc653d054e549a87d429a8b7 (patch)
treebd067936c811a26051f15c37986e0ffe5214cef9 /runtime/lua/vim/loader.lua
parentdfe19d6e0047ea2a2a75dff0c57f4c4de1c0196a (diff)
downloadrneovim-0804034c07ad5883bc653d054e549a87d429a8b7.tar.gz
rneovim-0804034c07ad5883bc653d054e549a87d429a8b7.tar.bz2
rneovim-0804034c07ad5883bc653d054e549a87d429a8b7.zip
fix(loader): cache path ambiguity #24491
Problem: cache paths are derived by replacing each reserved/filesystem- path-sensitive char with a `%` char in the original path. With this method, two different files at two different paths (each containing `%` chars) can erroneously resolve to the very same cache path in certain edge-cases. Solution: derive cache paths by url-encoding the original (path) instead using `vim.uri_encode()` with `"rfc2396"`. Increment `Loader.VERSION` to denote this change.
Diffstat (limited to 'runtime/lua/vim/loader.lua')
-rw-r--r--runtime/lua/vim/loader.lua5
1 files changed, 3 insertions, 2 deletions
diff --git a/runtime/lua/vim/loader.lua b/runtime/lua/vim/loader.lua
index 4f4722b0c3..e08ccba701 100644
--- a/runtime/lua/vim/loader.lua
+++ b/runtime/lua/vim/loader.lua
@@ -1,4 +1,5 @@
local uv = vim.uv
+local uri_encode = vim.uri_encode
--- @type (fun(modename: string): fun()|string)[]
local loaders = package.loaders
@@ -33,7 +34,7 @@ M.enabled = false
---@field _rtp_key string
---@field _hashes? table<string, CacheHash>
local Loader = {
- VERSION = 3,
+ VERSION = 4,
---@type table<string, table<string,ModuleInfo>>
_indexed = {},
---@type table<string, string[]>
@@ -99,7 +100,7 @@ end
---@return string file_name
---@private
function Loader.cache_file(name)
- local ret = M.path .. '/' .. name:gsub('[/\\:]', '%%')
+ local ret = ('%s/%s'):format(M.path, uri_encode(name, 'rfc2396'))
return ret:sub(-4) == '.lua' and (ret .. 'c') or (ret .. '.luac')
end