mirror of
https://github.com/nginx/nginx.git
synced 2024-12-12 18:29:00 +08:00
allow "~", "~*", "^~", and "=" before location name without space
This commit is contained in:
parent
9a1d46684c
commit
22f6d86cba
@ -39,6 +39,8 @@ static char *ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd,
|
|||||||
void *dummy);
|
void *dummy);
|
||||||
static char *ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd,
|
static char *ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd,
|
||||||
void *dummy);
|
void *dummy);
|
||||||
|
static ngx_int_t ngx_http_core_regex_location(ngx_conf_t *cf,
|
||||||
|
ngx_http_core_loc_conf_t *clcf, ngx_str_t *regex, ngx_uint_t caseless);
|
||||||
|
|
||||||
static char *ngx_http_core_types(ngx_conf_t *cf, ngx_command_t *cmd,
|
static char *ngx_http_core_types(ngx_conf_t *cf, ngx_command_t *cmd,
|
||||||
void *conf);
|
void *conf);
|
||||||
@ -2182,8 +2184,10 @@ static char *
|
|||||||
ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
|
ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
|
||||||
{
|
{
|
||||||
char *rv;
|
char *rv;
|
||||||
|
u_char *mod;
|
||||||
|
size_t len;
|
||||||
|
ngx_str_t *value, *name;
|
||||||
ngx_uint_t i;
|
ngx_uint_t i;
|
||||||
ngx_str_t *value;
|
|
||||||
ngx_conf_t save;
|
ngx_conf_t save;
|
||||||
ngx_http_module_t *module;
|
ngx_http_module_t *module;
|
||||||
ngx_http_conf_ctx_t *ctx, *pctx;
|
ngx_http_conf_ctx_t *ctx, *pctx;
|
||||||
@ -2225,45 +2229,32 @@ ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
|
|||||||
value = cf->args->elts;
|
value = cf->args->elts;
|
||||||
|
|
||||||
if (cf->args->nelts == 3) {
|
if (cf->args->nelts == 3) {
|
||||||
if (value[1].len == 1 && value[1].data[0] == '=') {
|
|
||||||
clcf->name = value[2];
|
len = value[1].len;
|
||||||
|
mod = value[1].data;
|
||||||
|
name = &value[2];
|
||||||
|
|
||||||
|
if (len == 1 && mod[0] == '=') {
|
||||||
|
|
||||||
|
clcf->name = *name;
|
||||||
clcf->exact_match = 1;
|
clcf->exact_match = 1;
|
||||||
|
|
||||||
} else if (value[1].len == 2
|
} else if (len == 2 && mod[0] == '^' && mod[1] == '~') {
|
||||||
&& value[1].data[0] == '^'
|
|
||||||
&& value[1].data[1] == '~')
|
clcf->name = *name;
|
||||||
{
|
|
||||||
clcf->name = value[2];
|
|
||||||
clcf->noregex = 1;
|
clcf->noregex = 1;
|
||||||
|
|
||||||
} else if ((value[1].len == 1 && value[1].data[0] == '~')
|
} else if (len == 1 && mod[0] == '~') {
|
||||||
|| (value[1].len == 2
|
|
||||||
&& value[1].data[0] == '~'
|
|
||||||
&& value[1].data[1] == '*'))
|
|
||||||
{
|
|
||||||
#if (NGX_PCRE)
|
|
||||||
ngx_str_t err;
|
|
||||||
u_char errstr[NGX_MAX_CONF_ERRSTR];
|
|
||||||
|
|
||||||
err.len = NGX_MAX_CONF_ERRSTR;
|
if (ngx_http_core_regex_location(cf, clcf, name, 0) != NGX_OK) {
|
||||||
err.data = errstr;
|
|
||||||
|
|
||||||
clcf->regex = ngx_regex_compile(&value[2],
|
|
||||||
value[1].len == 2 ? NGX_REGEX_CASELESS: 0,
|
|
||||||
cf->pool, &err);
|
|
||||||
|
|
||||||
if (clcf->regex == NULL) {
|
|
||||||
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", err.data);
|
|
||||||
return NGX_CONF_ERROR;
|
return NGX_CONF_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
clcf->name = value[2];
|
} else if (len == 2 && mod[0] == '~' && mod[1] == '*') {
|
||||||
#else
|
|
||||||
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
if (ngx_http_core_regex_location(cf, clcf, name, 1) != NGX_OK) {
|
||||||
"the using of the regex \"%V\" "
|
return NGX_CONF_ERROR;
|
||||||
"requires PCRE library", &value[2]);
|
}
|
||||||
return NGX_CONF_ERROR;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
||||||
@ -2273,10 +2264,47 @@ ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
clcf->name = value[1];
|
name = &value[1];
|
||||||
|
|
||||||
if (value[1].data[0] == '@') {
|
if (name->data[0] == '=') {
|
||||||
clcf->named = 1;
|
|
||||||
|
clcf->name.len = name->len - 1;
|
||||||
|
clcf->name.data = name->data + 1;
|
||||||
|
clcf->exact_match = 1;
|
||||||
|
|
||||||
|
} else if (name->data[0] == '^' && name->data[1] == '~') {
|
||||||
|
|
||||||
|
clcf->name.len = name->len - 2;
|
||||||
|
clcf->name.data = name->data + 2;
|
||||||
|
clcf->noregex = 1;
|
||||||
|
|
||||||
|
} else if (name->data[0] == '~') {
|
||||||
|
|
||||||
|
name->len--;
|
||||||
|
name->data++;
|
||||||
|
|
||||||
|
if (name->data[0] == '*') {
|
||||||
|
|
||||||
|
name->len--;
|
||||||
|
name->data++;
|
||||||
|
|
||||||
|
if (ngx_http_core_regex_location(cf, clcf, name, 1) != NGX_OK) {
|
||||||
|
return NGX_CONF_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if (ngx_http_core_regex_location(cf, clcf, name, 0) != NGX_OK) {
|
||||||
|
return NGX_CONF_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
clcf->name = *name;
|
||||||
|
|
||||||
|
if (name->data[0] == '@') {
|
||||||
|
clcf->named = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2314,13 +2342,13 @@ ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
|
|||||||
return NGX_CONF_ERROR;
|
return NGX_CONF_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
len = pclcf->name.len;
|
||||||
|
|
||||||
#if (NGX_PCRE)
|
#if (NGX_PCRE)
|
||||||
if (clcf->regex == NULL
|
if (clcf->regex == NULL
|
||||||
&& ngx_strncmp(clcf->name.data, pclcf->name.data, pclcf->name.len)
|
&& ngx_strncmp(clcf->name.data, pclcf->name.data, len) != 0)
|
||||||
!= 0)
|
|
||||||
#else
|
#else
|
||||||
if (ngx_strncmp(clcf->name.data, pclcf->name.data, pclcf->name.len)
|
if (ngx_strncmp(clcf->name.data, pclcf->name.data, len) != 0)
|
||||||
!= 0)
|
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
||||||
@ -2346,6 +2374,40 @@ ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static ngx_int_t
|
||||||
|
ngx_http_core_regex_location(ngx_conf_t *cf, ngx_http_core_loc_conf_t *clcf,
|
||||||
|
ngx_str_t *regex, ngx_uint_t caseless)
|
||||||
|
{
|
||||||
|
#if (NGX_PCRE)
|
||||||
|
ngx_str_t err;
|
||||||
|
u_char errstr[NGX_MAX_CONF_ERRSTR];
|
||||||
|
|
||||||
|
err.len = NGX_MAX_CONF_ERRSTR;
|
||||||
|
err.data = errstr;
|
||||||
|
|
||||||
|
clcf->regex = ngx_regex_compile(regex, caseless ? NGX_REGEX_CASELESS: 0,
|
||||||
|
cf->pool, &err);
|
||||||
|
|
||||||
|
if (clcf->regex == NULL) {
|
||||||
|
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", err.data);
|
||||||
|
return NGX_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
clcf->name = *regex;
|
||||||
|
|
||||||
|
return NGX_OK;
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
||||||
|
"the using of the regex \"%V\" requires PCRE library",
|
||||||
|
regex);
|
||||||
|
return NGX_ERROR;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
ngx_http_core_types(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
ngx_http_core_types(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user