[nginx] Script: simplified copy capture codes.

Maxim Dounin mdounin at mdounin.ru
Fri Jun 19 20:36:43 UTC 2026


details:   http://freenginx.org/hg/nginx/rev/0fd5e6155817
branches:  
changeset: 9556:0fd5e6155817
user:      Maxim Dounin <mdounin at mdounin.ru>
date:      Fri Jun 19 22:54:19 2026 +0300
description:
Script: simplified copy capture codes.

diffstat:

 src/http/ngx_http_script.c     |  22 ++++++++++++----------
 src/stream/ngx_stream_script.c |  10 +++++++---
 2 files changed, 19 insertions(+), 13 deletions(-)

diffs (105 lines):

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