# HG changeset patch # User Kim Alvefur # Date 1356077042 -3600 # Node ID b125892e187c7de6ca35868a78b468b49a0da360 # Parent a77c6eba461e9abeea4bc149bbc17f2c23322cad mod_http_files: Escape paths in redirects diff -r a77c6eba461e -r b125892e187c plugins/mod_http_files.lua --- a/plugins/mod_http_files.lua Fri Dec 21 08:27:14 2012 +0100 +++ b/plugins/mod_http_files.lua Fri Dec 21 09:04:02 2012 +0100 @@ -12,6 +12,7 @@ local os_date = os.date; local open = io.open; local stat = lfs.attributes; +local build_path = require"socket.url".build_path; local http_base = module:get_option_string("http_files_dir", module:get_option_string("http_path", "www_files")); local dir_indices = module:get_option("http_files_index", { "index.html", "index.htm" }); @@ -78,7 +79,9 @@ data = data.data; elseif attr.mode == "directory" then if full_path:sub(-1) ~= "/" then - response_headers.location = orig_path.."/"; + local path = { is_absolute = true, is_directory = true }; + for dir in orig_path:gmatch("[^/]+") do path[#path+1]=dir; end + response_headers.location = build_path(path); return 301; end for i=1,#dir_indices do