diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2020-04-16 13:45:50 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-04-16 13:45:50 -0300 |
| commit | af03c342789dce9799af2f41fda42f7d36467b85 (patch) | |
| tree | 4b94a18d272133419cb3e26d6dc0c6b5ed382595 /src | |
| parent | 708fed20d013e69fd79d80f0b59a45a25eed3a00 (diff) | |
| download | luarocks-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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/luarocks/core/dir.lua | 13 |
1 files changed, 13 insertions, 0 deletions
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 = {} | |||
| 4 | local require = nil | 4 | local require = nil |
| 5 | -------------------------------------------------------------------------------- | 5 | -------------------------------------------------------------------------------- |
| 6 | 6 | ||
| 7 | local 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 | ||
| 14 | end | ||
| 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("/*$", "")) |
| 22 | end | 34 | end |
| 23 | 35 | ||
| @@ -29,6 +41,7 @@ end | |||
| 29 | function dir.split_url(url) | 41 | function 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" |
