Open rtzui opened 11 years ago
tl;dr
patch splitpath
in wsapi/common.lua
as following:
function _M.splitpath(filename)
local path, file = string.match(filename, "(.-)/?([^/\\]-)$")
if #path == 0 then path = "." end
return path, file
end
I met this problem recently. The main cause is that all HTTP servers implement CGI differently. In my case, I am using Caddy with caddy-cgi/v2 plugin.
File wsapi/common.lua
path, file = _M.splitpath(filename)
modname, ext = _M.splitext(file)
Here filename
is derived from CGI variable SCRIPT_FILENAME
and PATH_TRANSLATED
(see find_module
called in wsapi.cgi
).
function _M.splitpath(filename)
-- local path, file = string.match(filename, "^(.*)[/\\]([^/\\]*)$")
local path, file = string.match(filename, "(.-)/?([^/\\]-)$")
return path, file
end
splitpath
has a corner case, where strings like file.ext
, abc.lua
will fail. In my case, filename
becomes app.lua
so path
& file
both become nil
.
How to reproduce the error:
Run
thttpd -p 8000 -d . -c \*.cgi
as a webserverStart web browser, get:
The Problem seems to be that _M.find_file(filename) from common.lua gets only the name of the file to be run, not a path to it. But I'm not sure. I'm, by the way, using lua5.1.