[njs] Modules: checking for duplicate js_set variables.

Dmitry Volyntsev xeioex at nginx.com
Tue Apr 9 05:48:00 UTC 2024


details:   https://hg.nginx.org/njs/rev/6fb1aca4eeaf
branches:  
changeset: 2313:6fb1aca4eeaf
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Mon Apr 08 22:47:24 2024 -0700
description:
Modules: checking for duplicate js_set variables.

This closes #700 issue on Github.

diffstat:

 nginx/ngx_http_js_module.c   |  6 ++++++
 nginx/ngx_stream_js_module.c |  6 ++++++
 2 files changed, 12 insertions(+), 0 deletions(-)

diffs (32 lines):

diff -r 1c8b6b9bc06c -r 6fb1aca4eeaf nginx/ngx_http_js_module.c
--- a/nginx/ngx_http_js_module.c	Thu Apr 04 16:07:53 2024 -0700
+++ b/nginx/ngx_http_js_module.c	Mon Apr 08 22:47:24 2024 -0700
@@ -4773,6 +4773,12 @@ ngx_http_js_set(ngx_conf_t *cf, ngx_comm
 
     *fname = value[2];
 
+    if (v->get_handler == ngx_http_js_variable_set) {
+        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+                           "variable \"%V\" is already declared", &value[1]);
+        return NGX_CONF_ERROR;
+    }
+
     v->get_handler = ngx_http_js_variable_set;
     v->data = (uintptr_t) fname;
 
diff -r 1c8b6b9bc06c -r 6fb1aca4eeaf nginx/ngx_stream_js_module.c
--- a/nginx/ngx_stream_js_module.c	Thu Apr 04 16:07:53 2024 -0700
+++ b/nginx/ngx_stream_js_module.c	Mon Apr 08 22:47:24 2024 -0700
@@ -2217,6 +2217,12 @@ ngx_stream_js_set(ngx_conf_t *cf, ngx_co
 
     *fname = value[2];
 
+    if (v->get_handler == ngx_stream_js_variable_set) {
+        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+                           "variable \"%V\" is already declared", &value[1]);
+        return NGX_CONF_ERROR;
+    }
+
     v->get_handler = ngx_stream_js_variable_set;
     v->data = (uintptr_t) fname;
 


More information about the nginx-devel mailing list