[PATCH] Tests: added rewrite test with nested captures

Maxim Dounin mdounin at mdounin.ru
Mon May 25 01:11:50 UTC 2026


# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1779658307 -10800
#      Mon May 25 00:31:47 2026 +0300
# Node ID 48645a6fd3936888837abcc3e0edc3a2e65047ca
# Parent  2688ca1e99fb3b56e8837c7d45c23e2f1c9eacdd
Tests: added rewrite test with nested captures.

diff --git a/rewrite.t b/rewrite.t
--- a/rewrite.t
+++ b/rewrite.t
@@ -21,7 +21,7 @@ use Test::Nginx;
 select STDERR; $| = 1;
 select STDOUT; $| = 1;
 
-my $t = Test::Nginx->new()->has(qw/http rewrite proxy/)->plan(24)
+my $t = Test::Nginx->new()->has(qw/http rewrite proxy/)->plan(25)
 	->write_file_expand('nginx.conf', <<'EOF');
 
 %%TEST_GLOBALS%%
@@ -137,6 +137,11 @@ http {
             return 200 "uri:$uri args:$args";
         }
 
+        location /capture_nested {
+            rewrite ^((.*)) /?c=$1&d=$2;
+            return 200 "uri:$uri args:$args";
+        }
+
         location /break {
             rewrite ^ /return200;
             break;
@@ -256,6 +261,19 @@ like(http_get('/capture_another/%25?a=b'
 
 }
 
+TODO: {
+local $TODO = 'not yet'
+	unless $t->has_version('1.31.2');
+todo_skip 'might coredump', 1
+	unless $t->has_version('1.31.2')
+	or $ENV{TEST_NGINX_UNSAFE};
+
+like(http_get('/capture_nested/%25?a=b'),
+	qr!^uri:/ args:c=/capture_nested/%25&d=/capture_nested/%25&a=b$!ms,
+	'escape with nested captures');
+
+}
+
 # break
 
 like(http_get('/break'), qr/200/, 'valid_location reset');



More information about the nginx-devel mailing list