util.prosodyctl: Handle os.execute in Lua 5.2 returning true when command terminates...
[prosody.git] / plugins / mod_http_files.lua
index 097f83468b41725e218794664d27970d2919cb7d..3b60249559c6e7e42bee94699d0f14ba122f7c4b 100644 (file)
@@ -1,7 +1,7 @@
 -- Prosody IM
 -- Copyright (C) 2008-2010 Matthew Wild
 -- Copyright (C) 2008-2010 Waqas Hussain
--- 
+--
 -- This project is MIT/X11 licensed. Please see the
 -- COPYING file in the source package for more information.
 --
@@ -75,6 +75,9 @@ function sanitize_path(path)
                        out[c] = component;
                end
        end
+       if path:sub(-1,-1) == "/" then
+               out[c+1] = "";
+       end
        return "/"..table.concat(out, "/");
 end
 
@@ -95,7 +98,7 @@ function serve(opts)
                end
                path = sanitized_path;
                local orig_path = sanitize_path(request.path);
-               local full_path = base_path .. (path and "/"..path or ""):gsub("/", path_sep);
+               local full_path = base_path .. (path or ""):gsub("/", path_sep);
                local attr = stat(full_path:match("^.*[^\\/]")); -- Strip trailing path separator because Windows
                if not attr then
                        return 404;