lua: ensure that PATH_INFO starts with a slash
authorJo-Philipp Wich <jo@mein.io>
Tue, 25 Oct 2016 15:10:14 +0000 (17:10 +0200)
committerJo-Philipp Wich <jo@mein.io>
Tue, 25 Oct 2016 15:45:59 +0000 (17:45 +0200)
When calculating the matching prefix length, make sure to not take the trailing
slash into account in order to ensure that the resulting PATH_INFO string
always starts with a slash.

This ensures that an url like "/foo" against the matching prefix "/" or
"/foo/bar" against "/foo/" result in "/foo" and "/bar" respectively.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
lua.c

diff --git a/lua.c b/lua.c
index 213490483e469f9c929b507db0afc9e0c8b5cf4a..3efe22bd9e21a0d4d924698937f39243b18566d4 100644 (file)
--- a/lua.c
+++ b/lua.c
@@ -222,6 +222,10 @@ static void lua_main(struct client *cl, struct path_info *pi, char *url)
                        pi->query = str + 1;
                path_len = str - url;
        }
+
+       if (prefix_len > 0 && conf.lua_prefix[prefix_len - 1] == '/')
+               prefix_len--;
+
        if (path_len > prefix_len) {
                lua_pushlstring(L, url + prefix_len,
                                path_len - prefix_len);