From 4d1eadae1ed745bd1b2f19caeea46a2258c5aac6 Mon Sep 17 00:00:00 2001 From: Jan Kneschke Date: Wed, 22 Feb 2006 12:50:56 +0000 Subject: [PATCH] handle 'foo.php... == foo.php' case on windows/dos git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-merge-1.4.x@1005 152afb58-edef-0310-8abb-c4023f1b3aa9 --- src/response.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/response.c b/src/response.c index d955ceca..05c834b7 100644 --- a/src/response.c +++ b/src/response.c @@ -320,6 +320,36 @@ handler_t http_response_prepare(server *srv, connection *con) { buffer_copy_string_buffer(con->physical.doc_root, con->conf.document_root); buffer_copy_string_buffer(con->physical.rel_path, con->uri.path); + /* strip dots from the end and spaces + * + * windows/dos handle those filenames as the same file + * + * foo == foo. == foo..... == "foo... " == "foo.. ./" + * + * This will affect in some cases PATHINFO + * + * */ + if (con->physical.rel_path->used > 1) { + buffer *b = con->physical.rel_path; + size_t i; + + if (b->used > 2 && + b->ptr[b->used-2] == '/' && + (b->ptr[b->used-3] == ' ' || + b->ptr[b->used-3] == '.')) { + b->ptr[b->used--] = '\0'; + } + + for (i = b->used - 2; b->used > 1; i--) { + if (b->ptr[i] == ' ' || + b->ptr[i] == '.') { + b->ptr[b->used--] = '\0'; + } else { + break; + } + } + } + if (con->conf.log_request_handling) { log_error_write(srv, __FILE__, __LINE__, "s", "-- before doc_root"); log_error_write(srv, __FILE__, __LINE__, "sb", "Doc-Root :", con->physical.doc_root);