From e8ecf31ad5fa768e00853091b1c442d19ab37d73 Mon Sep 17 00:00:00 2001 From: Paul Kulchenko Date: Sun, 1 Oct 2023 22:45:44 -0700 Subject: [PATCH] Fix handling of redbean assets without extension Fixes #902 --- tool/net/redbean.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tool/net/redbean.c b/tool/net/redbean.c index a9fc59ceb..c1529689e 100644 --- a/tool/net/redbean.c +++ b/tool/net/redbean.c @@ -4957,12 +4957,15 @@ static const char *GetContentTypeExt(const char *path, size_t n) { if ((r = FindContentType(path, n))) return r; // 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); lua_pushlightuserdata(L, (void *)&ctIdx); // push address as unique key 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) r = FreeLater(strdup(lua_tostring(L, -1))); lua_settop(L, top);