From: Maxim Dounin Date: Fri, 19 Jun 2026 19:54:19 +0000 (+0300) Subject: Script: simplified copy capture codes. X-Git-Tag: release-1.31.3~7 X-Git-Url: http://git.kaiwu.me/http/doc/$%7BGITURL%7D/static/gitweb.js?a=commitdiff_plain;h=28219209e0b4f9e155fd8bd91ab81b8ac30628f2;p=nginx.git Script: simplified copy capture codes. Signed-off-by: Roman Arutyunyan Origin: --- diff --git a/src/http/ngx_http_script.c b/src/http/ngx_http_script.c index ddae0c1cb..8a7ba57e2 100644 --- a/src/http/ngx_http_script.c +++ b/src/http/ngx_http_script.c @@ -1346,6 +1346,7 @@ ngx_http_script_copy_capture_len_code(ngx_http_script_engine_t *e) { int *cap; u_char *p; + size_t len; ngx_uint_t n; ngx_http_request_t *r; ngx_http_script_copy_capture_code_t *code; @@ -1361,17 +1362,17 @@ ngx_http_script_copy_capture_len_code(ngx_http_script_engine_t *e) if (n < r->ncaptures) { cap = r->captures; + len = cap[n + 1] - cap[n]; if ((e->is_args || e->quote) && (e->request->quoted_uri || e->request->plus_in_uri)) { - p = r->captures_data; + p = r->captures_data + cap[n]; + + return len + 2 * ngx_escape_uri(NULL, p, len, NGX_ESCAPE_ARGS); - return cap[n + 1] - cap[n] - + 2 * ngx_escape_uri(NULL, &p[cap[n]], cap[n + 1] - cap[n], - NGX_ESCAPE_ARGS); } else { - return cap[n + 1] - cap[n]; + return len; } } @@ -1384,6 +1385,7 @@ ngx_http_script_copy_capture_code(ngx_http_script_engine_t *e) { int *cap; u_char *p, *pos; + size_t len; ngx_uint_t n; ngx_http_request_t *r; ngx_http_script_copy_capture_code_t *code; @@ -1401,16 +1403,16 @@ ngx_http_script_copy_capture_code(ngx_http_script_engine_t *e) if (n < r->ncaptures) { cap = r->captures; - p = r->captures_data; + len = cap[n + 1] - cap[n]; + p = r->captures_data + cap[n]; if ((e->is_args || e->quote) && (e->request->quoted_uri || e->request->plus_in_uri)) { - e->pos = (u_char *) ngx_escape_uri(pos, &p[cap[n]], - cap[n + 1] - cap[n], - NGX_ESCAPE_ARGS); + e->pos = (u_char *) ngx_escape_uri(pos, p, len, NGX_ESCAPE_ARGS); + } else { - e->pos = ngx_copy(pos, &p[cap[n]], cap[n + 1] - cap[n]); + e->pos = ngx_copy(pos, p, len); } } diff --git a/src/stream/ngx_stream_script.c b/src/stream/ngx_stream_script.c index 175e44194..d1f256caf 100644 --- a/src/stream/ngx_stream_script.c +++ b/src/stream/ngx_stream_script.c @@ -896,6 +896,7 @@ size_t ngx_stream_script_copy_capture_len_code(ngx_stream_script_engine_t *e) { int *cap; + size_t len; ngx_uint_t n; ngx_stream_session_t *s; ngx_stream_script_copy_capture_code_t *code; @@ -910,7 +911,8 @@ ngx_stream_script_copy_capture_len_code(ngx_stream_script_engine_t *e) if (n < s->ncaptures) { cap = s->captures; - return cap[n + 1] - cap[n]; + len = cap[n + 1] - cap[n]; + return len; } return 0; @@ -922,6 +924,7 @@ ngx_stream_script_copy_capture_code(ngx_stream_script_engine_t *e) { int *cap; u_char *p, *pos; + size_t len; ngx_uint_t n; ngx_stream_session_t *s; ngx_stream_script_copy_capture_code_t *code; @@ -938,8 +941,9 @@ ngx_stream_script_copy_capture_code(ngx_stream_script_engine_t *e) if (n < s->ncaptures) { cap = s->captures; - p = s->captures_data; - e->pos = ngx_copy(pos, &p[cap[n]], cap[n + 1] - cap[n]); + len = cap[n + 1] - cap[n]; + p = s->captures_data + cap[n]; + e->pos = ngx_copy(pos, p, len); } ngx_log_debug2(NGX_LOG_DEBUG_STREAM, e->session->connection->log, 0,