diff options
author | Ryan Hartlage <ryanplusplus@gmail.com> | 2018-08-01 15:52:02 -0400 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2018-08-01 16:52:02 -0300 |
commit | 8e39a526b57a2f9cf021f38cd9ffc8f88abd68fd (patch) | |
tree | 211aca4381b17aa117f492ae98c266dcd9c3d4cb | |
parent | c02b5989301312dfee02c195497e119bd0c73b85 (diff) | |
download | luarocks-8e39a526b57a2f9cf021f38cd9ffc8f88abd68fd.tar.gz luarocks-8e39a526b57a2f9cf021f38cd9ffc8f88abd68fd.tar.bz2 luarocks-8e39a526b57a2f9cf021f38cd9ffc8f88abd68fd.zip |
Do not rewrite path in util.cleanup_path if the desired version is a substring of the version (#868)
* Do not rewrite path in util.cleanup_path if the desired version is a substring of the version
* Improve test coverage for core.util.cleanup_path
-rw-r--r-- | spec/util_spec.lua | 14 | ||||
-rw-r--r-- | src/luarocks/core/util.lua | 6 |
2 files changed, 19 insertions, 1 deletions
diff --git a/spec/util_spec.lua b/spec/util_spec.lua index cbdde095..930a5aea 100644 --- a/spec/util_spec.lua +++ b/spec/util_spec.lua | |||
@@ -155,4 +155,18 @@ describe("Luarocks util test #unit", function() | |||
155 | assert.truthy(result:find("[\"e\"] = \"4\"", 1, true)) | 155 | assert.truthy(result:find("[\"e\"] = \"4\"", 1, true)) |
156 | end) | 156 | end) |
157 | end) | 157 | end) |
158 | |||
159 | describe("core.util.cleanup_path", function() | ||
160 | it("rewrites versions that do not match the provided version", function() | ||
161 | local expected = 'a/b/lua/5.3/?.lua;a/b/c/lua/5.3/?.lua' | ||
162 | local result = core_util.cleanup_path('a/b/lua/5.2/?.lua;a/b/c/lua/5.3/?.lua', ';', '5.3') | ||
163 | assert.are.equal(expected, result) | ||
164 | end) | ||
165 | |||
166 | it("does not rewrite versions for which the provided version is a substring", function() | ||
167 | local expected = 'a/b/lua/5.3/?.lua;a/b/c/lua/5.3.4/?.lua' | ||
168 | local result = core_util.cleanup_path('a/b/lua/5.2/?.lua;a/b/c/lua/5.3.4/?.lua', ';', '5.3') | ||
169 | assert.are.equal(expected, result) | ||
170 | end) | ||
171 | end) | ||
158 | end) | 172 | end) |
diff --git a/src/luarocks/core/util.lua b/src/luarocks/core/util.lua index daec9d05..5f5c0fe1 100644 --- a/src/luarocks/core/util.lua +++ b/src/luarocks/core/util.lua | |||
@@ -166,7 +166,11 @@ function util.cleanup_path(list, sep, lua_version) | |||
166 | for _, part in ipairs(parts) do | 166 | for _, part in ipairs(parts) do |
167 | part = part:gsub("//", "/") | 167 | part = part:gsub("//", "/") |
168 | if lua_version then | 168 | if lua_version then |
169 | part = part:gsub("/lua/[%d.]+/", "/lua/"..lua_version.."/") | 169 | part = part:gsub("/lua/([%d.]+)/", function(part_version) |
170 | if part_version:sub(1, #lua_version) ~= lua_version then | ||
171 | return "/lua/"..lua_version.."/" | ||
172 | end | ||
173 | end) | ||
170 | end | 174 | end |
171 | if not entries[part] then | 175 | if not entries[part] then |
172 | table.insert(final, part) | 176 | table.insert(final, part) |