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. --- src/luarocks/core/dir.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src') 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