aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2020-04-16 13:45:50 -0300
committerGitHub <noreply@github.com>2020-04-16 13:45:50 -0300
commitaf03c342789dce9799af2f41fda42f7d36467b85 (patch)
tree4b94a18d272133419cb3e26d6dc0c6b5ed382595
parent708fed20d013e69fd79d80f0b59a45a25eed3a00 (diff)
downloadluarocks-af03c342789dce9799af2f41fda42f7d36467b85.tar.gz
luarocks-af03c342789dce9799af2f41fda42f7d36467b85.tar.bz2
luarocks-af03c342789dce9799af2f41fda42f7d36467b85.zip
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.
-rw-r--r--spec/cmd_spec.lua4
-rw-r--r--src/luarocks/core/dir.lua13
2 files changed, 17 insertions, 0 deletions
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()
46 it("passes if given a valid path with Lua", function() 46 it("passes if given a valid path with Lua", function()
47 assert.truthy(run.luarocks("--lua-dir=" .. test_env.testing_paths.luadir)) 47 assert.truthy(run.luarocks("--lua-dir=" .. test_env.testing_paths.luadir))
48 end) 48 end)
49
50 it("passes if given a quoted path with Lua", function()
51 assert.truthy(run.luarocks("--lua-dir '" .. test_env.testing_paths.luadir .. "'"))
52 end)
49 end) 53 end)
50 54
51 describe("--lua-version", function() 55 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 = {}
4local require = nil 4local require = nil
5-------------------------------------------------------------------------------- 5--------------------------------------------------------------------------------
6 6
7local function unquote(c)
8 local first, last = c:sub(1,1), c:sub(-1)
9 if (first == '"' and last == '"') or
10 (first == "'" and last == "'") then
11 return c:sub(2,-2)
12 end
13 return c
14end
15
7--- Describe a path in a cross-platform way. 16--- Describe a path in a cross-platform way.
8-- Use this function to avoid platform-specific directory 17-- Use this function to avoid platform-specific directory
9-- separators in other modules. Removes trailing slashes from 18-- separators in other modules. Removes trailing slashes from
@@ -18,6 +27,9 @@ function dir.path(...)
18 while t[1] == "" do 27 while t[1] == "" do
19 table.remove(t, 1) 28 table.remove(t, 1)
20 end 29 end
30 for i, c in ipairs(t) do
31 t[i] = unquote(c)
32 end
21 return (table.concat(t, "/"):gsub("([^:])/+", "%1/"):gsub("^/+", "/"):gsub("/*$", "")) 33 return (table.concat(t, "/"):gsub("([^:])/+", "%1/"):gsub("^/+", "/"):gsub("/*$", ""))
22end 34end
23 35
@@ -29,6 +41,7 @@ end
29function dir.split_url(url) 41function dir.split_url(url)
30 assert(type(url) == "string") 42 assert(type(url) == "string")
31 43
44 url = unquote(url)
32 local protocol, pathname = url:match("^([^:]*)://(.*)") 45 local protocol, pathname = url:match("^([^:]*)://(.*)")
33 if not protocol then 46 if not protocol then
34 protocol = "file" 47 protocol = "file"