[njs] Fixed parsing of invalid for statement.
Vadim Zhestikov
v.zhestikov at f5.com
Sat Jul 1 02:51:11 UTC 2023
details: https://hg.nginx.org/njs/rev/2c532e7c29ac
branches:
changeset: 2172:2c532e7c29ac
user: Vadim Zhestikov <v.zhestikov at f5.com>
date: Fri Jun 30 19:49:45 2023 -0700
description:
Fixed parsing of invalid for statement.
diffstat:
src/njs_parser.c | 16 ++++++++++++++--
src/test/njs_unit_test.c | 3 +++
2 files changed, 17 insertions(+), 2 deletions(-)
diffs (46 lines):
diff -r 494796d6d7f8 -r 2c532e7c29ac src/njs_parser.c
--- a/src/njs_parser.c Fri Jun 30 17:03:11 2023 -0700
+++ b/src/njs_parser.c Fri Jun 30 19:49:45 2023 -0700
@@ -5491,6 +5491,18 @@ njs_parser_iteration_statement_for(njs_p
static njs_int_t
+njs_parser_for_var_in_of_expression_chk_fail(njs_parser_t *parser,
+ njs_lexer_token_t *token, njs_queue_link_t *current)
+{
+ if (parser->ret != NJS_OK) {
+ return njs_parser_failed(parser);
+ }
+
+ return njs_parser_for_var_in_of_expression(parser, token, current);
+}
+
+
+static njs_int_t
njs_parser_for_expression_map_reparse(njs_parser_t *parser,
njs_lexer_token_t *token, njs_queue_link_t *current)
{
@@ -5517,8 +5529,8 @@ njs_parser_for_expression_map_reparse(nj
*text = token->text;
- return njs_parser_after(parser, current, text, 1,
- njs_parser_for_var_in_of_expression);
+ return njs_parser_after(parser, current, text, 0,
+ njs_parser_for_var_in_of_expression_chk_fail);
}
return njs_parser_stack_pop(parser);
diff -r 494796d6d7f8 -r 2c532e7c29ac src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c Fri Jun 30 17:03:11 2023 -0700
+++ b/src/test/njs_unit_test.c Fri Jun 30 19:49:45 2023 -0700
@@ -2975,6 +2975,9 @@ static njs_unit_test_t njs_test[] =
{ njs_str("for(var``>0; 0 ;) ;"),
njs_str("SyntaxError: Unexpected token \"`\" in 1") },
+ { njs_str("for(i;;)for(-new+3;;)break;"),
+ njs_str("SyntaxError: Unexpected token \"+\" in 1") },
+
/* switch. */
{ njs_str("switch"),
More information about the nginx-devel
mailing list