mirror of
https://github.com/neovim/neovim.git
synced 2025-09-07 03:48:18 +00:00
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.
This commit is contained in:
@@ -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
|
||||
|
||||
|
Reference in New Issue
Block a user