From 0804034c07ad5883bc653d054e549a87d429a8b7 Mon Sep 17 00:00:00 2001 From: Tyler Miller Date: Tue, 1 Aug 2023 08:28:28 -0700 Subject: 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. --- runtime/lua/vim/loader.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'runtime/lua/vim/loader.lua') 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 local Loader = { - VERSION = 3, + VERSION = 4, ---@type table> _indexed = {}, ---@type table @@ -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 -- cgit