[njs] Fixed rest parameter parsing without binding identifier.

Alexander Borisov alexander.borisov at nginx.com
Tue Jun 29 14:09:07 UTC 2021


details:   https://hg.nginx.org/njs/rev/45c470a2d710
branches:  
changeset: 1672:45c470a2d710
user:      Alexander Borisov <alexander.borisov at nginx.com>
date:      Tue Jun 29 17:08:23 2021 +0300
description:
Fixed rest parameter parsing without binding identifier.

This closes #400 issue on GitHub.

diffstat:

 src/njs_parser.c         |  9 +++++++++
 src/test/njs_unit_test.c |  6 ++++++
 2 files changed, 15 insertions(+), 0 deletions(-)

diffs (35 lines):

diff -r fe1888cc2e3c -r 45c470a2d710 src/njs_parser.c
--- a/src/njs_parser.c	Tue Jun 29 17:08:21 2021 +0300
+++ b/src/njs_parser.c	Tue Jun 29 17:08:23 2021 +0300
@@ -6791,6 +6791,15 @@ njs_parser_formal_parameters(njs_parser_
 
         njs_lexer_consume_token(parser->lexer, 1);
 
+        token = njs_lexer_token(parser->lexer, 0);
+        if (token == NULL) {
+            return NJS_ERROR;
+        }
+
+        if (!njs_lexer_token_is_binding_identifier(token)) {
+            return njs_parser_failed(parser);
+        }
+
         lambda->rest_parameters = 1;
 
         return NJS_OK;
diff -r fe1888cc2e3c -r 45c470a2d710 src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c	Tue Jun 29 17:08:21 2021 +0300
+++ b/src/test/njs_unit_test.c	Tue Jun 29 17:08:23 2021 +0300
@@ -9330,6 +9330,12 @@ static njs_unit_test_t  njs_test[] =
     { njs_str("function f(a,...rest) { }; f.length"),
       njs_str("1") },
 
+    { njs_str("function f(...) {}"),
+      njs_str("SyntaxError: Unexpected token \")\" in 1") },
+
+    { njs_str("(function (...) {})()"),
+      njs_str("SyntaxError: Unexpected token \")\" in 1") },
+
     { njs_str("function f(a,b) { }; var ff = f.bind(f, 1); ff.length"),
       njs_str("1") },
 


More information about the nginx-devel mailing list