[PATCH 1 of 3] Script: simplified copy capture codes
Maxim Dounin
mdounin at mdounin.ru
Mon Jun 8 17:37:21 UTC 2026
# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1780936492 -10800
# Mon Jun 08 19:34:52 2026 +0300
# Node ID ee56583e9b7e2d80bb5d6efc18147cdb13295b43
# Parent 5930e96ebd5a3d93bd719210e837f7281fc4f6d9
Script: simplified copy capture codes.
diff --git a/src/http/ngx_http_script.c b/src/http/ngx_http_script.c
--- a/src/http/ngx_http_script.c
+++ b/src/http/ngx_http_script.c
@@ -1310,6 +1310,7 @@ ngx_http_script_copy_capture_len_code(ng
{
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;
@@ -1325,17 +1326,17 @@ ngx_http_script_copy_capture_len_code(ng
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 cap[n + 1] - cap[n]
- + 2 * ngx_escape_uri(NULL, &p[cap[n]], cap[n + 1] - cap[n],
- NGX_ESCAPE_ARGS);
+ return len + 2 * ngx_escape_uri(NULL, p, len, NGX_ESCAPE_ARGS);
+
} else {
- return cap[n + 1] - cap[n];
+ return len;
}
}
@@ -1348,6 +1349,7 @@ ngx_http_script_copy_capture_code(ngx_ht
{
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;
@@ -1365,16 +1367,16 @@ ngx_http_script_copy_capture_code(ngx_ht
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
--- a/src/stream/ngx_stream_script.c
+++ b/src/stream/ngx_stream_script.c
@@ -888,6 +888,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;
@@ -902,7 +903,8 @@ ngx_stream_script_copy_capture_len_code(
if (n < s->ncaptures) {
cap = s->captures;
- return cap[n + 1] - cap[n];
+ len = cap[n + 1] - cap[n];
+ return len;
}
return 0;
@@ -914,6 +916,7 @@ ngx_stream_script_copy_capture_code(ngx_
{
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;
@@ -930,8 +933,9 @@ ngx_stream_script_copy_capture_code(ngx_
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,
More information about the nginx-devel
mailing list