mod_http_files: Fix traceback when serving a non-wildcard path (fixes #611)
authorKim Alvefur <zash@zash.se>
Thu, 3 Mar 2016 14:28:07 +0000 (15:28 +0100)
committerKim Alvefur <zash@zash.se>
Thu, 3 Mar 2016 14:28:07 +0000 (15:28 +0100)
plugins/mod_http_files.lua

index 6275cca5d7fc2a07fc072cd9b53587fe2fabeef7..097f83468b41725e218794664d27970d2919cb7d 100644 (file)
@@ -56,6 +56,7 @@ end
 
 local urldecode = require "util.http".urldecode;
 function sanitize_path(path)
+       if not path then return end
        local out = {};
 
        local c = 0;
@@ -88,10 +89,11 @@ function serve(opts)
        local directory_index = opts.directory_index;
        local function serve_file(event, path)
                local request, response = event.request, event.response;
-               path = sanitize_path(path);
-               if not path then
+               local sanitized_path = sanitize_path(path);
+               if path and not sanitized_path then
                        return 400;
                end
+               path = sanitized_path;
                local orig_path = sanitize_path(request.path);
                local full_path = base_path .. (path and "/"..path or ""):gsub("/", path_sep);
                local attr = stat(full_path:match("^.*[^\\/]")); -- Strip trailing path separator because Windows