Fix handling of redbean assets without extension

Fixes #902
This commit is contained in:
Paul Kulchenko 2023-10-01 22:45:44 -07:00 committed by Justine Tunney
parent a201e694ee
commit e8ecf31ad5
No known key found for this signature in database
GPG key ID: BE714B4575D6E328

View file

@ -4957,12 +4957,15 @@ static const char *GetContentTypeExt(const char *path, size_t n) {
if ((r = FindContentType(path, n))) return r; if ((r = FindContentType(path, n))) return r;
// extract the last .; use the entire path if none is present // extract the last .; use the entire path if none is present
if ((e = strrchr(path, '.'))) path = e + 1; if ((e = memrchr(path, '.', n))) {
n -= e - path + 1;
path = e + 1;
}
top = lua_gettop(L); top = lua_gettop(L);
lua_pushlightuserdata(L, (void *)&ctIdx); // push address as unique key lua_pushlightuserdata(L, (void *)&ctIdx); // push address as unique key
CHECK_EQ(lua_gettable(L, LUA_REGISTRYINDEX), LUA_TTABLE); CHECK_EQ(lua_gettable(L, LUA_REGISTRYINDEX), LUA_TTABLE);
lua_pushstring(L, path); lua_pushlstring(L, path, n);
if (lua_gettable(L, -2) == LUA_TSTRING) if (lua_gettable(L, -2) == LUA_TSTRING)
r = FreeLater(strdup(lua_tostring(L, -1))); r = FreeLater(strdup(lua_tostring(L, -1)));
lua_settop(L, top); lua_settop(L, top);