[njs] Fixed labeled empty statement.

Vadim Zhestikov v.zhestikov at f5.com
Mon Oct 24 17:27:20 UTC 2022


details:   https://hg.nginx.org/njs/rev/594821c68b83
branches:  
changeset: 1981:594821c68b83
user:      Vadim Zhestikov <v.zhestikov at f5.com>
date:      Mon Oct 24 07:48:28 2022 -0700
description:
Fixed labeled empty statement.

This fixes #593 issue on Github.

diffstat:

 src/njs_parser.c         |  64 ++++++++++++++++++++++++-----------------------
 src/test/njs_unit_test.c |   3 ++
 2 files changed, 36 insertions(+), 31 deletions(-)

diffs (89 lines):

diff -r ebc48ac9f656 -r 594821c68b83 src/njs_parser.c
--- a/src/njs_parser.c	Fri Oct 21 18:48:39 2022 -0700
+++ b/src/njs_parser.c	Mon Oct 24 07:48:28 2022 -0700
@@ -4701,39 +4701,41 @@ njs_parser_statement_after(njs_parser_t 
 
     new_node = parser->node;
 
-    if (new_node->hoist) {
-        child = &njs_parser_chain_top(parser);
-
-        while (*child != NULL) {
-            node = *child;
-
-            if (node->hoist) {
-                break;
+    if (new_node != NULL) {
+        if (new_node->hoist) {
+            child = &njs_parser_chain_top(parser);
+
+            while (*child != NULL) {
+                node = *child;
+
+                if (node->hoist) {
+                    break;
+                }
+
+                child = &node->left;
             }
 
-            child = &node->left;
-        }
-
-        last = *child;
-    }
-
-    stmt = njs_parser_node_new(parser, NJS_TOKEN_STATEMENT);
-    if (njs_slow_path(stmt == NULL)) {
-        return NJS_ERROR;
-    }
-
-    stmt->hoist = new_node->hoist;
-    stmt->left = last;
-    stmt->right = new_node;
-
-    *child = stmt;
-
-    top = (child != &parser->target) ? njs_parser_chain_top(parser)
-                                     : stmt;
-
-    parser->node = top;
-
-    njs_parser_chain_top_set(parser, top);
+            last = *child;
+        }
+
+        stmt = njs_parser_node_new(parser, NJS_TOKEN_STATEMENT);
+        if (njs_slow_path(stmt == NULL)) {
+            return NJS_ERROR;
+        }
+
+        stmt->hoist = new_node->hoist;
+        stmt->left = last;
+        stmt->right = new_node;
+
+        *child = stmt;
+
+        top = (child != &parser->target) ? njs_parser_chain_top(parser)
+                                         : stmt;
+
+        parser->node = top;
+
+       njs_parser_chain_top_set(parser, top);
+    }
 
     return njs_parser_stack_pop(parser);
 }
diff -r ebc48ac9f656 -r 594821c68b83 src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c	Fri Oct 21 18:48:39 2022 -0700
+++ b/src/test/njs_unit_test.c	Mon Oct 24 07:48:28 2022 -0700
@@ -3159,6 +3159,9 @@ static njs_unit_test_t  njs_test[] =
     { njs_str("a:\n\n1"),
       njs_str("1") },
 
+    { njs_str("a:;"),
+      njs_str("undefined") },
+
     { njs_str("a:\n\n"),
       njs_str("SyntaxError: Unexpected end of input in 3") },
 



More information about the nginx-devel mailing list