From 70901d805d8a133a2cc45414ee025da182c51a1a Mon Sep 17 00:00:00 2001 From: Stefan Fritsch Date: Fri, 21 Jan 2011 12:51:57 +0000 Subject: [PATCH] Ignore leading dots when looking for mime extensions PR 50434 git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1061791 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES | 3 +++ modules/http/mod_mime.c | 19 +++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 044b83df843..b5695bb9f08 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,9 @@ Changes with Apache 2.3.11 + *) mod_mime: Ignore leading dots when looking for mime extensions. + PR 50434 [Stefan Fritsch] + *) core: Add support to set variables with the 'Define' directive. The variables that can then be used in the config using the ${VAR} syntax known from envvar interpolation. [Stefan Fritsch] diff --git a/modules/http/mod_mime.c b/modules/http/mod_mime.c index 6277daa367a..390707d38b3 100644 --- a/modules/http/mod_mime.c +++ b/modules/http/mod_mime.c @@ -755,7 +755,7 @@ static int find_ct(request_rec *r) mime_dir_config *conf; apr_array_header_t *exception_list; char *ext; - const char *fn, *type, *charset = NULL, *resource_name; + const char *fn, *fntmp, *type, *charset = NULL, *resource_name; int found_metadata = 0; if (r->finfo.filetype == APR_DIR) { @@ -788,12 +788,27 @@ static int find_ct(request_rec *r) ++fn; } + /* The exception list keeps track of those filename components that * are not associated with extensions indicating metadata. * The base name is always the first exception (i.e., "txt.html" has * a basename of "txt" even though it might look like an extension). + * Leading dots are considered to be part of the base name (a file named + * ".png" is likely not a png file but just a hidden file called png). */ - ext = ap_getword(r->pool, &fn, '.'); + fntmp = fn; + while (*fntmp == '.') + fntmp++; + fntmp = ap_strchr_c(fntmp, '.'); + if (fntmp) { + ext = apr_pstrmemdup(r->pool, fn, fntmp - fn); + fn = fntmp + 1; + } + else { + ext = apr_pstrdup(r->pool, fn); + fn += strlen(fn); + } + *((const char **)apr_array_push(exception_list)) = ext; /* Parse filename extensions which can be in any order -- 2.47.2