Mercurial > prosody-hg
comparison plugins/mod_http_files.lua @ 7228:b5b7ae2901e6
mod_http_files: Fix traceback when serving a non-wildcard path (fixes #611)
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Thu, 03 Mar 2016 15:28:07 +0100 |
| parents | e9f07febafb3 |
| children | dcc8ed11173c |
comparison
equal
deleted
inserted
replaced
| 7223:f911f929ca6c | 7228:b5b7ae2901e6 |
|---|---|
| 54 forbidden_chars_pattern = "[/%z\001-\031\127\"*:<>?|]" | 54 forbidden_chars_pattern = "[/%z\001-\031\127\"*:<>?|]" |
| 55 end | 55 end |
| 56 | 56 |
| 57 local urldecode = require "util.http".urldecode; | 57 local urldecode = require "util.http".urldecode; |
| 58 function sanitize_path(path) | 58 function sanitize_path(path) |
| 59 if not path then return end | |
| 59 local out = {}; | 60 local out = {}; |
| 60 | 61 |
| 61 local c = 0; | 62 local c = 0; |
| 62 for component in path:gmatch("([^/]+)") do | 63 for component in path:gmatch("([^/]+)") do |
| 63 component = urldecode(component); | 64 component = urldecode(component); |
| 86 local base_path = opts.path; | 87 local base_path = opts.path; |
| 87 local dir_indices = opts.index_files or dir_indices; | 88 local dir_indices = opts.index_files or dir_indices; |
| 88 local directory_index = opts.directory_index; | 89 local directory_index = opts.directory_index; |
| 89 local function serve_file(event, path) | 90 local function serve_file(event, path) |
| 90 local request, response = event.request, event.response; | 91 local request, response = event.request, event.response; |
| 91 path = sanitize_path(path); | 92 local sanitized_path = sanitize_path(path); |
| 92 if not path then | 93 if path and not sanitized_path then |
| 93 return 400; | 94 return 400; |
| 94 end | 95 end |
| 96 path = sanitized_path; | |
| 95 local orig_path = sanitize_path(request.path); | 97 local orig_path = sanitize_path(request.path); |
| 96 local full_path = base_path .. (path and "/"..path or ""):gsub("/", path_sep); | 98 local full_path = base_path .. (path and "/"..path or ""):gsub("/", path_sep); |
| 97 local attr = stat(full_path:match("^.*[^\\/]")); -- Strip trailing path separator because Windows | 99 local attr = stat(full_path:match("^.*[^\\/]")); -- Strip trailing path separator because Windows |
| 98 if not attr then | 100 if not attr then |
| 99 return 404; | 101 return 404; |
