[njs] Fixed double declaration detection in modules.

Vadim Zhestikov v.zhestikov at f5.com
Fri Oct 7 01:30:02 UTC 2022


details:   https://hg.nginx.org/njs/rev/16442fa970ee
branches:  
changeset: 1975:16442fa970ee
user:      Vadim Zhestikov <v.zhestikov at f5.com>
date:      Thu Oct 06 18:28:52 2022 -0700
description:
Fixed double declaration detection in modules.

diffstat:

 src/njs_variable.c       |  15 +++++++++------
 src/test/njs_unit_test.c |   4 ++++
 2 files changed, 13 insertions(+), 6 deletions(-)

diffs (41 lines):

diff -r 80b59b59b7d8 -r 16442fa970ee src/njs_variable.c
--- a/src/njs_variable.c	Fri Sep 30 17:40:57 2022 -0700
+++ b/src/njs_variable.c	Thu Oct 06 18:28:52 2022 -0700
@@ -222,14 +222,17 @@ njs_variable_scope_find(njs_parser_t *pa
         return root;
     }
 
-    module = parser->vm->options.module || parser->module;
+    if (scope->parent == NULL) {
+        module = parser->vm->options.module || parser->module;
 
-    if (module) {
-        if (type == NJS_VARIABLE_FUNCTION
-            || var->type == NJS_VARIABLE_FUNCTION)
-        {
-            goto failed;
+        if (module) {
+            if (type == NJS_VARIABLE_FUNCTION
+                || var->type == NJS_VARIABLE_FUNCTION)
+            {
+                goto failed;
+            }
         }
+
     }
 
     return root;
diff -r 80b59b59b7d8 -r 16442fa970ee src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c	Fri Sep 30 17:40:57 2022 -0700
+++ b/src/test/njs_unit_test.c	Thu Oct 06 18:28:52 2022 -0700
@@ -21296,6 +21296,10 @@ static njs_unit_test_t  njs_module_test[
 
     { njs_str("{ var f = 1; } function f() {};"),
       njs_str("SyntaxError: \"f\" has already been declared in 1") },
+
+    { njs_str("function f(v) {var f = v;}; f(1); f"),
+      njs_str("[object Function]") },
+
 };
 
 



More information about the nginx-devel mailing list