From 4edb65cfa1a32e62a98e38bf21cda9542e0bda2d Mon Sep 17 00:00:00 2001 From: Glenn Strauss Date: Thu, 28 Apr 2016 13:23:29 -0400 Subject: [PATCH] [core] preserve PATH_INFO case on case-insensitive fs (fixes #406) attempt to preserve PATH_INFO case even when the URI is mapped onto a case-insensitive file system. NTFS (Windows) is case-insensitive (even though it is case-preserving) HFS+ (Mac OS X) can be formatted to be case-insensitive x-ref: "... PATH_INFO ... improperly converted to lowercase" https://redmine.lighttpd.net/issues/406 --- src/response.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/response.c b/src/response.c index fc2df712..389b079f 100644 --- a/src/response.c +++ b/src/response.c @@ -696,13 +696,24 @@ handler_t http_response_prepare(server *srv, connection *con) { /* we have a PATHINFO */ if (pathinfo) { - buffer_copy_string(con->request.pathinfo, pathinfo); + size_t len = strlen(pathinfo), reqlen; + if (con->conf.force_lowercase_filenames + && len <= (reqlen = buffer_string_length(con->request.uri)) + && 0 == strncasecmp(con->request.uri->ptr + reqlen - len, pathinfo, len)) { + /* attempt to preserve case-insensitive PATH_INFO + * (works in common case where mod_alias, mod_magnet, and other modules + * have not modified the PATH_INFO portion of request URI, or did so + * with exactly the PATH_INFO desired) */ + buffer_copy_string_len(con->request.pathinfo, con->request.uri->ptr + reqlen - len, len); + } else { + buffer_copy_string_len(con->request.pathinfo, pathinfo, len); + } /* * shorten uri.path */ - buffer_string_set_length(con->uri.path, buffer_string_length(con->uri.path) - strlen(pathinfo)); + buffer_string_set_length(con->uri.path, buffer_string_length(con->uri.path) - len); } if (con->conf.log_request_handling) { -- 2.11.4.GIT