aboutsummaryrefslogtreecommitdiff
path: root/nginx/t/js_dup_set.t
diff options
context:
space:
mode:
authorDmitry Volyntsev <xeioex@nginx.com>2024-04-22 17:51:45 -0700
committerDmitry Volyntsev <xeioex@nginx.com>2024-04-22 17:51:45 -0700
commit5ab8d47c6d59ce21feae1541d4b7acb1289570dc (patch)
tree667f251a8286c035f9d1a661eba35478478d7f6c /nginx/t/js_dup_set.t
parent8b22e722b345c383e789e98533200e98975e5425 (diff)
downloadnjs-5ab8d47c6d59ce21feae1541d4b7acb1289570dc.tar.gz
njs-5ab8d47c6d59ce21feae1541d4b7acb1289570dc.zip
Modules: improved checking for duplicate js_set variables.
Since 6fb1aca4eeaf (0.8.4) the identical js_set variables introduced as a part of an include file that is shared amongst multiple vhosts are rejected during configuration parsing. The patch ignores duplicate js_set variables when they refer to the same JS function. This fixes #705 issue on Github.
Diffstat (limited to 'nginx/t/js_dup_set.t')
-rw-r--r--nginx/t/js_dup_set.t74
1 files changed, 74 insertions, 0 deletions
diff --git a/nginx/t/js_dup_set.t b/nginx/t/js_dup_set.t
new file mode 100644
index 00000000..317eaffa
--- /dev/null
+++ b/nginx/t/js_dup_set.t
@@ -0,0 +1,74 @@
+#!/usr/bin/perl
+
+# (C) Dmitry Volyntsev
+# (C) Nginx, Inc.
+
+# Tests for http njs module, duplicate identical js_set directives.
+
+###############################################################################
+
+use warnings;
+use strict;
+
+use Test::More;
+
+BEGIN { use FindBin; chdir($FindBin::Bin); }
+
+use lib 'lib';
+use Test::Nginx;
+
+###############################################################################
+
+select STDERR; $| = 1;
+select STDOUT; $| = 1;
+
+my $t = Test::Nginx->new()->has(qw/http/)
+ ->write_file_expand('nginx.conf', <<'EOF');
+
+%%TEST_GLOBALS%%
+
+daemon off;
+
+events {
+}
+
+http {
+ %%TEST_GLOBALS_HTTP%%
+
+ js_import test.js;
+
+ server {
+ listen 127.0.0.1:8080;
+ server_name localhost;
+
+ location /set1 {
+ js_set $test test.foo;
+ return 200 set1:$test;
+ }
+
+ location /set2 {
+ js_set $test test.foo;
+ return 200 set2:$test;
+ }
+ }
+}
+
+EOF
+
+$t->write_file('test.js', <<EOF);
+ function foo(r) {
+ return 42;
+ }
+
+ export default {foo};
+
+EOF
+
+$t->try_run('no njs')->plan(2);
+
+###############################################################################
+
+like(http_get('/set1'), qr/set1:42/, '/set1 location');
+like(http_get('/set2'), qr/set2:42/, '/set2 location');
+
+###############################################################################