From af03c342789dce9799af2f41fda42f7d36467b85 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Thu, 16 Apr 2020 13:45:50 -0300 Subject: Handle quoting at the application level (#1181) This is done to support Windows. Unix handles quoting at the shell level. While quotes are technically valid as part of Unix names, I don't expect this pathological case to be something we need to support. Closes #1173. --- spec/cmd_spec.lua | 4 ++++ src/luarocks/core/dir.lua | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/spec/cmd_spec.lua b/spec/cmd_spec.lua index 705b8845..2c3f9f47 100644 --- a/spec/cmd_spec.lua +++ b/spec/cmd_spec.lua @@ -46,6 +46,10 @@ describe("LuaRocks command line #integration", function() it("passes if given a valid path with Lua", function() assert.truthy(run.luarocks("--lua-dir=" .. test_env.testing_paths.luadir)) end) + + it("passes if given a quoted path with Lua", function() + assert.truthy(run.luarocks("--lua-dir '" .. test_env.testing_paths.luadir .. "'")) + end) end) describe("--lua-version", function() diff --git a/src/luarocks/core/dir.lua b/src/luarocks/core/dir.lua index 59b7749c..d346ec4f 100644 --- a/src/luarocks/core/dir.lua +++ b/src/luarocks/core/dir.lua @@ -4,6 +4,15 @@ local dir = {} local require = nil -------------------------------------------------------------------------------- +local function unquote(c) + local first, last = c:sub(1,1), c:sub(-1) + if (first == '"' and last == '"') or + (first == "'" and last == "'") then + return c:sub(2,-2) + end + return c +end + --- Describe a path in a cross-platform way. -- Use this function to avoid platform-specific directory -- separators in other modules. Removes trailing slashes from @@ -18,6 +27,9 @@ function dir.path(...) while t[1] == "" do table.remove(t, 1) end + for i, c in ipairs(t) do + t[i] = unquote(c) + end return (table.concat(t, "/"):gsub("([^:])/+", "%1/"):gsub("^/+", "/"):gsub("/*$", "")) end @@ -29,6 +41,7 @@ end function dir.split_url(url) assert(type(url) == "string") + url = unquote(url) local protocol, pathname = url:match("^([^:]*)://(.*)") if not protocol then protocol = "file" -- cgit v1.2.3-55-g6feb