Alexander Borisov
May 17, 2021 01:38PM
details: https://hg.nginx.org/njs/rev/7b70ee90ead8
branches:
changeset: 1637:7b70ee90ead8
user: Alexander Borisov <alexander.borisov@nginx.com>
date: Mon May 17 20:35:35 2021 +0300
description:
Fixed parsing case/default in an unclosed function block in switch.

diffstat:

src/njs_parser.c | 13 ++++++++++++-
src/test/njs_unit_test.c | 18 ++++++++++++++++++
2 files changed, 30 insertions(+), 1 deletions(-)

diffs (65 lines):

diff -r 637bc81166a6 -r 7b70ee90ead8 src/njs_parser.c
--- a/src/njs_parser.c Thu May 06 16:07:09 2021 +0300
+++ b/src/njs_parser.c Mon May 17 20:35:35 2021 +0300
@@ -4713,7 +4713,10 @@ njs_parser_statement_list_next(njs_parse
if (parser->ret != NJS_OK) {
if (token->type != NJS_TOKEN_CLOSE_BRACE) {
parser->node = parser->target;
- return njs_parser_stack_pop(parser);
+
+ (void) njs_parser_stack_pop(parser);
+
+ return parser->ret;
}

return njs_parser_failed(parser);
@@ -6098,6 +6101,10 @@ njs_parser_switch_case_block(njs_parser_
{
parser->target->right->right = parser->node;

+ if (parser->ret != NJS_OK && parser->target->scope != parser->scope) {
+ return njs_parser_failed(parser);
+ }
+
njs_parser_next(parser, njs_parser_switch_case);

return NJS_OK;
@@ -6153,6 +6160,10 @@ njs_parser_switch_case_block_wo_def(njs_
parser->target->right = parser->node;
}

+ if (parser->ret != NJS_OK && parser->target->scope != parser->scope) {
+ return njs_parser_failed(parser);
+ }
+
njs_parser_next(parser, njs_parser_switch_case_wo_def);

return NJS_OK;
diff -r 637bc81166a6 -r 7b70ee90ead8 src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c Thu May 06 16:07:09 2021 +0300
+++ b/src/test/njs_unit_test.c Mon May 17 20:35:35 2021 +0300
@@ -2958,6 +2958,24 @@ static njs_unit_test_t njs_test[] =
"map((v)=>{switch(v) { case isNaN: return 1; default: return 0;}})"),
njs_str("1,0,0") },

+ { njs_str("switch (1) {case 1: ii > 1; ii => default:}"),
+ njs_str("SyntaxError: Unexpected token \"default\" in 1") },
+
+ { njs_str("switch (1) {case 1: ii > 1; var a = functin () {default:}"),
+ njs_str("SyntaxError: Unexpected token \"{\" in 1") },
+
+ { njs_str("switch (1) {default: ii > 1; ii => case 2:}"),
+ njs_str("SyntaxError: Unexpected token \"case\" in 1") },
+
+ { njs_str("switch (1) {default: ii > 1; var a = functin () {case 2:}"),
+ njs_str("SyntaxError: Unexpected token \"{\" in 1") },
+
+ { njs_str("switch (1) {case 1: ii > 1; ii => case 2:}"),
+ njs_str("SyntaxError: Unexpected token \"case\" in 1") },
+
+ { njs_str("switch (1) {case 1: ii > 1; var a = functin () {case 2:}"),
+ njs_str("SyntaxError: Unexpected token \"{\" in 1") },
+
/* continue. */

{ njs_str("continue"),
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Fixed parsing case/default in an unclosed function block in switch.

Alexander Borisov 156 May 17, 2021 01:38PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 62
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready