10ea73
diff --git a/docs/manual/mod/core.html.en b/docs/manual/mod/core.html.en
10ea73
index 0a24bc8..20d1e5a 100644
10ea73
--- a/docs/manual/mod/core.html.en
10ea73
+++ b/docs/manual/mod/core.html.en
10ea73
@@ -97,6 +97,7 @@ available
10ea73
 
  • MaxRangeOverlaps
  • 10ea73
     
  • MaxRangeReversals
  • 10ea73
     
  • MaxRanges
  • 10ea73
    +
  • MergeSlashes
  • 10ea73
     
  • MergeTrailers
  • 10ea73
     
  • Mutex
  • 10ea73
     
  • NameVirtualHost
  • 10ea73
    @@ -3465,6 +3466,30 @@ resource 
    10ea73
     
    10ea73
     
    10ea73
     
    top
    10ea73
    +
    10ea73
    +
    10ea73
    +Description:Controls whether the server merges consecutive slashes in URLs. 
    10ea73
    +Syntax:MergeSlashes ON | OFF
    10ea73
    +Default:MergeSlashes ON
    10ea73
    +Context:server config, virtual host
    10ea73
    +Status:Core
    10ea73
    +Module:core
    10ea73
    +Compatibility:Available in Apache HTTP Server 2.4.6 in Red Hat Enterprise Linux 7
    10ea73
    +
    10ea73
    +    

    By default, the server merges (or collapses) multiple consecutive slash

    10ea73
    +       ('/') characters in the path component of the request URL.

    10ea73
    +
    10ea73
    +    

    When mapping URL's to the filesystem, these multiple slashes are not

    10ea73
    +       significant.  However, URL's handled other ways, such as by CGI or proxy,
    10ea73
    +       might prefer to retain the significance of multiple consecutive slashes. 
    10ea73
    +       In these cases MergeSlashes can be set to 
    10ea73
    +       OFF to retain the multiple consecutive slashes.  In these
    10ea73
    +       configurations, regular expressions used in the configuration file that match
    10ea73
    +       the path component of the URL (LocationMatch,
    10ea73
    +       RewriteRule, ...) need to take into account multiple 
    10ea73
    +       consecutive slashes.

    10ea73
    +
    10ea73
    +
    top
    10ea73
     
    10ea73
     
    10ea73
     Description:Determines whether trailers are merged into headers
    10ea73
    --- a/include/http_core.h	2019/03/18 08:49:19	1855736
    10ea73
    +++ b/include/http_core.h	2019/03/18 08:49:59	1855737
    10ea73
    @@ -740,7 +740,7 @@
    10ea73
     #define AP_HTTP_METHODS_LENIENT       1
    10ea73
     #define AP_HTTP_METHODS_REGISTERED    2
    10ea73
         char http_methods;
    10ea73
    -
    10ea73
    +    unsigned int merge_slashes;
    10ea73
     } core_server_config;
    10ea73
     
    10ea73
     /* for AddOutputFiltersByType in core.c */
    10ea73
    diff --git a/include/httpd.h b/include/httpd.h
    10ea73
    index 65392f8..99f7f04 100644
    10ea73
    --- a/include/httpd.h
    10ea73
    +++ b/include/httpd.h
    10ea73
    @@ -1697,11 +1697,21 @@ AP_DECLARE(int) ap_unescape_url_keep2f(char *url, int decode_slashes);
    10ea73
     AP_DECLARE(int) ap_unescape_urlencoded(char *query);
    10ea73
     
    10ea73
     /**
    10ea73
    - * Convert all double slashes to single slashes
    10ea73
    - * @param name The string to convert
    10ea73
    + * Convert all double slashes to single slashes, except where significant
    10ea73
    + * to the filesystem on the current platform.
    10ea73
    + * @param name The string to convert, assumed to be a filesystem path
    10ea73
      */
    10ea73
     AP_DECLARE(void) ap_no2slash(char *name);
    10ea73
     
    10ea73
    +/**
    10ea73
    + * Convert all double slashes to single slashes, except where significant
    10ea73
    + * to the filesystem on the current platform.
    10ea73
    + * @param name The string to convert
    10ea73
    + * @param is_fs_path if set to 0, the significance of any double-slashes is 
    10ea73
    + *        ignored.
    10ea73
    + */
    10ea73
    +AP_DECLARE(void) ap_no2slash_ex(char *name, int is_fs_path);
    10ea73
    +
    10ea73
     /**
    10ea73
      * Remove all ./ and xx/../ substrings from a file name. Also remove
    10ea73
      * any leading ../ or /../ substrings.
    10ea73
    diff --git a/server/request.c b/server/request.c
    10ea73
    index dbe3e07..d5c558a 100644
    10ea73
    --- a/server/request.c
    10ea73
    +++ b/server/request.c
    10ea73
    @@ -167,6 +167,8 @@ AP_DECLARE(int) ap_process_request_internal(request_rec *r)
    10ea73
         int file_req = (r->main && r->filename);
    10ea73
         int access_status;
    10ea73
         core_dir_config *d;
    10ea73
    +    core_server_config *sconf =
    10ea73
    +        ap_get_core_module_config(r->server->module_config);
    10ea73
     
    10ea73
         /* Ignore embedded %2F's in path for proxy requests */
    10ea73
         if (!r->proxyreq && r->parsed_uri.path) {
    10ea73
    @@ -191,6 +193,12 @@ AP_DECLARE(int) ap_process_request_internal(request_rec *r)
    10ea73
         }
    10ea73
     
    10ea73
         ap_getparents(r->uri);     /* OK --- shrinking transformations... */
    10ea73
    +    if (sconf->merge_slashes != AP_CORE_CONFIG_OFF) { 
    10ea73
    +        ap_no2slash(r->uri);
    10ea73
    +        if (r->parsed_uri.path) {
    10ea73
    +            ap_no2slash(r->parsed_uri.path);
    10ea73
    +        }
    10ea73
    +     }
    10ea73
     
    10ea73
         /* All file subrequests are a huge pain... they cannot bubble through the
    10ea73
          * next several steps.  Only file subrequests are allowed an empty uri,
    10ea73
    @@ -1411,20 +1419,7 @@ AP_DECLARE(int) ap_location_walk(request_rec *r)
    10ea73
     
    10ea73
         cache = prep_walk_cache(AP_NOTE_LOCATION_WALK, r);
    10ea73
         cached = (cache->cached != NULL);
    10ea73
    -
    10ea73
    -    /* Location and LocationMatch differ on their behaviour w.r.t. multiple
    10ea73
    -     * slashes.  Location matches multiple slashes with a single slash,
    10ea73
    -     * LocationMatch doesn't.  An exception, for backwards brokenness is
    10ea73
    -     * absoluteURIs... in which case neither match multiple slashes.
    10ea73
    -     */
    10ea73
    -    if (r->uri[0] != '/') {
    10ea73
    -        entry_uri = r->uri;
    10ea73
    -    }
    10ea73
    -    else {
    10ea73
    -        char *uri = apr_pstrdup(r->pool, r->uri);
    10ea73
    -        ap_no2slash(uri);
    10ea73
    -        entry_uri = uri;
    10ea73
    -    }
    10ea73
    +    entry_uri = r->uri;
    10ea73
     
    10ea73
         /* If we have an cache->cached location that matches r->uri,
    10ea73
          * and the vhost's list of locations hasn't changed, we can skip
    10ea73
    @@ -1491,7 +1486,7 @@ AP_DECLARE(int) ap_location_walk(request_rec *r)
    10ea73
                         pmatch = apr_palloc(rxpool, nmatch*sizeof(ap_regmatch_t));
    10ea73
                     }
    10ea73
     
    10ea73
    -                if (ap_regexec(entry_core->r, r->uri, nmatch, pmatch, 0)) {
    10ea73
    +                if (ap_regexec(entry_core->r, entry_uri, nmatch, pmatch, 0)) {
    10ea73
                         continue;
    10ea73
                     }
    10ea73
     
    10ea73
    @@ -1501,7 +1496,7 @@ AP_DECLARE(int) ap_location_walk(request_rec *r)
    10ea73
                             apr_table_setn(r->subprocess_env,
    10ea73
                                            ((const char **)entry_core->refs->elts)[i],
    10ea73
                                            apr_pstrndup(r->pool,
    10ea73
    -                                       r->uri + pmatch[i].rm_so,
    10ea73
    +                                       entry_uri + pmatch[i].rm_so,
    10ea73
                                            pmatch[i].rm_eo - pmatch[i].rm_so));
    10ea73
                         }
    10ea73
                     }
    10ea73
    diff --git a/server/util.c b/server/util.c
    10ea73
    index fd7a0a1..e0c558c 100644
    10ea73
    --- a/server/util.c
    10ea73
    +++ b/server/util.c
    10ea73
    @@ -561,16 +561,20 @@ AP_DECLARE(void) ap_getparents(char *name)
    10ea73
             name[l] = '\0';
    10ea73
         }
    10ea73
     }
    10ea73
    -
    10ea73
    -AP_DECLARE(void) ap_no2slash(char *name)
    10ea73
    +AP_DECLARE(void) ap_no2slash_ex(char *name, int is_fs_path)
    10ea73
     {
    10ea73
    +
    10ea73
         char *d, *s;
    10ea73
     
    10ea73
    +    if (!*name) {
    10ea73
    +        return;
    10ea73
    +    }
    10ea73
    +
    10ea73
         s = d = name;
    10ea73
     
    10ea73
     #ifdef HAVE_UNC_PATHS
    10ea73
         /* Check for UNC names.  Leave leading two slashes. */
    10ea73
    -    if (s[0] == '/' && s[1] == '/')
    10ea73
    +    if (is_fs_path && s[0] == '/' && s[1] == '/')
    10ea73
             *d++ = *s++;
    10ea73
     #endif
    10ea73
     
    10ea73
    @@ -587,6 +591,10 @@ AP_DECLARE(void) ap_no2slash(char *name)
    10ea73
         *d = '\0';
    10ea73
     }
    10ea73
     
    10ea73
    +AP_DECLARE(void) ap_no2slash(char *name)
    10ea73
    +{
    10ea73
    +    ap_no2slash_ex(name, 1);
    10ea73
    +}
    10ea73
     
    10ea73
     /*
    10ea73
      * copy at most n leading directories of s into d
    10ea73
    diff --git a/server/core.c b/server/core.c
    10ea73
    index b5ab429..a31f1e4 100644
    10ea73
    --- a/server/core.c
    10ea73
    +++ b/server/core.c
    10ea73
    @@ -493,6 +493,7 @@ static void *create_core_server_config(apr_pool_t *a, server_rec *s)
    10ea73
          */
    10ea73
     
    10ea73
         conf->trace_enable = AP_TRACE_UNSET;
    10ea73
    +    conf->merge_slashes = AP_CORE_CONFIG_UNSET;
    10ea73
     
    10ea73
         conf->protocols = apr_array_make(a, 5, sizeof(const char *));
    10ea73
         conf->protocols_honor_order = -1;
    10ea73
    @@ -561,7 +562,9 @@ static void *merge_core_server_configs(apr_pool_t *p, void *basev, void *virtv)
    10ea73
         conf->protocols_honor_order = ((virt->protocols_honor_order < 0)?
    10ea73
                                            base->protocols_honor_order :
    10ea73
                                            virt->protocols_honor_order);
    10ea73
    -    
    10ea73
    +
    10ea73
    +    AP_CORE_MERGE_FLAG(merge_slashes, conf, base, virt);
    10ea73
    +
    10ea73
         return conf;
    10ea73
     }
    10ea73
     
    10ea73
    @@ -1872,6 +1875,13 @@ static const char *set_qualify_redirect_url(cmd_parms *cmd, void *d_, int flag)
    10ea73
         return NULL;
    10ea73
     }
    10ea73
     
    10ea73
    +static const char *set_core_server_flag(cmd_parms *cmd, void *s_, int flag)
    10ea73
    +{
    10ea73
    +    core_server_config *conf =
    10ea73
    +        ap_get_core_module_config(cmd->server->module_config);
    10ea73
    +    return ap_set_flag_slot(cmd, conf, flag);
    10ea73
    +}
    10ea73
    +
    10ea73
     static const char *set_override_list(cmd_parms *cmd, void *d_, int argc, char *const argv[])
    10ea73
     {
    10ea73
         core_dir_config *d = d_;
    10ea73
    @@ -4598,6 +4608,10 @@ AP_INIT_ITERATE("HttpProtocolOptions", set_http_protocol_options, NULL, RSRC_CON
    10ea73
                     "'Unsafe' or 'Strict' (default). Sets HTTP acceptance rules"),
    10ea73
     AP_INIT_ITERATE("RegisterHttpMethod", set_http_method, NULL, RSRC_CONF,
    10ea73
                     "Registers non-standard HTTP methods"),
    10ea73
    +AP_INIT_FLAG("MergeSlashes", set_core_server_flag,
    10ea73
    +             (void *)APR_OFFSETOF(core_server_config, merge_slashes),
    10ea73
    +             RSRC_CONF,
    10ea73
    +             "Controls whether consecutive slashes in the URI path are merged"),
    10ea73
     { NULL }
    10ea73
     };
    10ea73