[nginx-tests] Tests: added test for positional captures with clo...
Maxim Dounin
mdounin at mdounin.ru
Fri Aug 14 06:14:04 UTC 2026
details: http://freenginx.org/hg/nginx-tests/rev/7c2b57e66ec2
branches:
changeset: 2087:7c2b57e66ec2
user: Maxim Dounin <mdounin at mdounin.ru>
date: Fri Aug 14 09:07:19 2026 +0300
description:
Tests: added test for positional captures with cloned subrequests.
diffstat:
proxy_cache_use_stale.t | 30 +++++++++++++++++++++++++++++-
1 files changed, 29 insertions(+), 1 deletions(-)
diffs (74 lines):
diff --git a/proxy_cache_use_stale.t b/proxy_cache_use_stale.t
--- a/proxy_cache_use_stale.t
+++ b/proxy_cache_use_stale.t
@@ -1,5 +1,6 @@
#!/usr/bin/perl
+# (C) Maxim Dounin
# (C) Sergey Kandaurov
# (C) Nginx, Inc.
@@ -25,7 +26,7 @@ select STDERR; $| = 1;
select STDOUT; $| = 1;
my $t = Test::Nginx->new()
- ->has(qw/http proxy cache rewrite limit_req ssi/)->plan(35)
+ ->has(qw/http proxy cache rewrite limit_req ssi map/)->plan(37)
->write_file_expand('nginx.conf', <<'EOF');
%%TEST_GLOBALS%%
@@ -42,6 +43,11 @@ http {
limit_req_zone $binary_remote_addr zone=slow:1m rate=10r/m;
+ map $uri $map {
+ volatile;
+ ~(nomatch) 1;
+ }
+
server {
listen 127.0.0.1:8080;
server_name localhost;
@@ -82,6 +88,11 @@ http {
proxy_pass http://127.0.0.1:8081/$1$name.html;
}
+ location ~ /map_(regexp.html) {
+ proxy_pass http://127.0.0.1:8081/$map$1;
+ add_header X-Cache-Status $upstream_cache_status:$map:$1;
+ }
+
location /updating/ {
proxy_pass http://127.0.0.1:8081/;
proxy_cache_use_stale updating;
@@ -172,6 +183,7 @@ get('/next/tt.html', 'max-age=1, stale-i
get('/t8.html', 'stale-while-revalidate=20');
get('/escape.htm%6C', 'max-age=1, stale-while-revalidate=20');
get('/regexp.html', 'max-age=1, stale-while-revalidate=20');
+get('/map_regexp.html', 'max-age=1, stale-while-revalidate=20');
sleep 2;
@@ -209,6 +221,22 @@ like(http_get('/t5.html'), qr/REVALIDATE
like(http_get('/regexp.html'), qr/STALE/, 's-w-r - regexp background update');
like(http_get('/regexp.html'), qr/HIT/, 's-w-r - regexp revalidated');
+TODO: {
+todo_skip 'might coredump', 2
+ unless $t->has_version('1.31.4')
+ or $ENV{TEST_NGINX_UNSAFE};
+local $TODO = 'not yet' unless $t->has_version('1.31.4');
+
+# when r->captures was reallocated but no match happened, positional captures
+# used uninitialized offsets from newly allocated r->captures
+
+like(http_get('/map_regexp.html'), qr/STALE::regexp.html/,
+ 's-w-r - regexp and map background update');
+like(http_get('/map_regexp.html'), qr/HIT::regexp.html/,
+ 's-w-r - regexp and map revalidated');
+
+}
+
# UPDATING while s-w-r
$t->write_file('t6.html', 'SEE-THAT');
More information about the nginx-devel
mailing list