mirror of
https://github.com/nginx/nginx.git
synced 2025-06-29 18:50:39 +08:00
Fixed alias in regex locations with limit_except/if.
The ngx_http_map_uri_to_path() function used clcf->regex to detect if it's working within a location given by a regular expression and have to replace full URI with alias (instead of a part matching the location prefix). This is incorrect due to clcf->regex being false in implicit locations created by if and limit_except. Fix is to preserve relevant information in clcf->alias instead, by setting it to NGX_MAX_SIZE_T_VALUE if an alias was specified in a regex location.
This commit is contained in:
parent
a785be76f6
commit
ffba0eeefb
@ -1245,10 +1245,8 @@ ngx_http_core_try_files_phase(ngx_http_request_t *r,
|
|||||||
if (!alias) {
|
if (!alias) {
|
||||||
reserve = len > r->uri.len ? len - r->uri.len : 0;
|
reserve = len > r->uri.len ? len - r->uri.len : 0;
|
||||||
|
|
||||||
#if (NGX_PCRE)
|
} else if (alias == NGX_MAX_SIZE_T_VALUE) {
|
||||||
} else if (clcf->regex) {
|
|
||||||
reserve = len;
|
reserve = len;
|
||||||
#endif
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
reserve = len > r->uri.len - alias ? len - (r->uri.len - alias) : 0;
|
reserve = len > r->uri.len - alias ? len - (r->uri.len - alias) : 0;
|
||||||
@ -1365,13 +1363,12 @@ ngx_http_core_try_files_phase(ngx_http_request_t *r,
|
|||||||
if (!alias) {
|
if (!alias) {
|
||||||
r->uri = path;
|
r->uri = path;
|
||||||
|
|
||||||
#if (NGX_PCRE)
|
} else if (alias == NGX_MAX_SIZE_T_VALUE) {
|
||||||
} else if (clcf->regex) {
|
|
||||||
if (!test_dir) {
|
if (!test_dir) {
|
||||||
r->uri = path;
|
r->uri = path;
|
||||||
r->add_uri_to_alias = 1;
|
r->add_uri_to_alias = 1;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
} else {
|
} else {
|
||||||
r->uri.len = alias + path.len;
|
r->uri.len = alias + path.len;
|
||||||
r->uri.data = ngx_pnalloc(r->pool, r->uri.len);
|
r->uri.data = ngx_pnalloc(r->pool, r->uri.len);
|
||||||
@ -2006,16 +2003,12 @@ ngx_http_map_uri_to_path(ngx_http_request_t *r, ngx_str_t *path,
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
#if (NGX_PCRE)
|
if (alias == NGX_MAX_SIZE_T_VALUE) {
|
||||||
ngx_uint_t captures;
|
reserved += r->add_uri_to_alias ? r->uri.len + 1 : 1;
|
||||||
|
|
||||||
captures = alias && clcf->regex;
|
} else {
|
||||||
|
reserved += r->uri.len - alias + 1;
|
||||||
reserved += captures ? r->add_uri_to_alias ? r->uri.len + 1 : 1
|
}
|
||||||
: r->uri.len - alias + 1;
|
|
||||||
#else
|
|
||||||
reserved += r->uri.len - alias + 1;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (ngx_http_script_run(r, path, clcf->root_lengths->elts, reserved,
|
if (ngx_http_script_run(r, path, clcf->root_lengths->elts, reserved,
|
||||||
clcf->root_values->elts)
|
clcf->root_values->elts)
|
||||||
@ -2033,8 +2026,7 @@ ngx_http_map_uri_to_path(ngx_http_request_t *r, ngx_str_t *path,
|
|||||||
*root_length = path->len - reserved;
|
*root_length = path->len - reserved;
|
||||||
last = path->data + *root_length;
|
last = path->data + *root_length;
|
||||||
|
|
||||||
#if (NGX_PCRE)
|
if (alias == NGX_MAX_SIZE_T_VALUE) {
|
||||||
if (captures) {
|
|
||||||
if (!r->add_uri_to_alias) {
|
if (!r->add_uri_to_alias) {
|
||||||
*last = '\0';
|
*last = '\0';
|
||||||
return last;
|
return last;
|
||||||
@ -2042,7 +2034,6 @@ ngx_http_map_uri_to_path(ngx_http_request_t *r, ngx_str_t *path,
|
|||||||
|
|
||||||
alias = 0;
|
alias = 0;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
last = ngx_cpystrn(last, r->uri.data + alias, r->uri.len - alias + 1);
|
last = ngx_cpystrn(last, r->uri.data + alias, r->uri.len - alias + 1);
|
||||||
@ -4476,6 +4467,7 @@ ngx_http_core_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|||||||
|
|
||||||
#if (NGX_PCRE)
|
#if (NGX_PCRE)
|
||||||
if (alias && clcf->regex) {
|
if (alias && clcf->regex) {
|
||||||
|
clcf->alias = NGX_MAX_SIZE_T_VALUE;
|
||||||
n = 1;
|
n = 1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user