From ed0524aa4f0d3875e9882ea745812bd27d3fb3be Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Mon, 27 Aug 2012 19:57:35 -0300 Subject: Fix handling of "/" in dir.path. Closes #80. --- src/luarocks/dir.lua | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/luarocks/dir.lua b/src/luarocks/dir.lua index 69968917..3de9e241 100644 --- a/src/luarocks/dir.lua +++ b/src/luarocks/dir.lua @@ -32,9 +32,10 @@ end --- Describe a path in a cross-platform way. -- Use this function to avoid platform-specific directory --- separators in other modules. If the first item contains a --- protocol descriptor (e.g. "http:"), paths are always constituted --- with forward slashes. +-- separators in other modules. Removes trailing slashes from +-- each component given, to avoid repeated separators. +-- Separators inside strings are kept, to handle URLs containing +-- protocols. -- @param ... strings representing directories -- @return string: a string with a platform-specific representation -- of the path. @@ -42,14 +43,14 @@ function path(...) local items = {...} local i = 1 while items[i] do - items[i] = items[i]:gsub("/*$", "") + items[i] = items[i]:gsub("(.+)/+$", "%1") if items[i] == "" then table.remove(items, i) else i = i + 1 end end - return table.concat(items, "/") + return (table.concat(items, "/"):gsub("(.+)/+$", "%1")) end --- Split protocol and path from an URL or local pathname. -- cgit v1.2.3-55-g6feb