[njs] Fixed division token in lexer.

Dmitry Volyntsev xeioex at nginx.com
Wed Aug 21 13:32:23 UTC 2019


details:   https://hg.nginx.org/njs/rev/4cc08cb772a2
branches:  
changeset: 1138:4cc08cb772a2
user:      hongzhidao <hongzhidao at gmail.com>
date:      Tue Aug 20 22:59:38 2019 -0400
description:
Fixed division token in lexer.

diffstat:

 src/njs_lexer.c          |  11 +++++++----
 src/test/njs_unit_test.c |   3 +++
 2 files changed, 10 insertions(+), 4 deletions(-)

diffs (50 lines):

diff -r 13161c0357e4 -r 4cc08cb772a2 src/njs_lexer.c
--- a/src/njs_lexer.c	Tue Aug 20 20:51:39 2019 +0300
+++ b/src/njs_lexer.c	Tue Aug 20 22:59:38 2019 -0400
@@ -504,7 +504,7 @@ njs_lexer_next_token(njs_lexer_t *lexer,
             token = njs_lexer_division(lexer, token);
 
             if (token != NJS_TOKEN_AGAIN) {
-                return token;
+                goto done;
             }
 
             continue;
@@ -557,8 +557,7 @@ njs_lexer_next_token(njs_lexer_t *lexer,
             /* Fall through. */
 
         default:
-            lt->text.length = lexer->start - lt->text.start;
-            return token;
+            goto done;
         }
 
     multi:
@@ -566,9 +565,13 @@ njs_lexer_next_token(njs_lexer_t *lexer,
         return njs_lexer_multi(lexer, lt, token, n, multi);
     }
 
+    token = NJS_TOKEN_END;
+
+done:
+
     lt->text.length = lexer->start - lt->text.start;
 
-    return NJS_TOKEN_END;
+    return token;
 }
 
 
diff -r 13161c0357e4 -r 4cc08cb772a2 src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c	Tue Aug 20 20:51:39 2019 +0300
+++ b/src/test/njs_unit_test.c	Tue Aug 20 22:59:38 2019 -0400
@@ -66,6 +66,9 @@ static njs_unit_test_t  njs_test[] =
     { njs_str("var \n a, \n b; b"),
       njs_str("undefined") },
 
+    { njs_str("var a / ="),
+      njs_str("SyntaxError: Unexpected token \"/\" in 1") },
+
     { njs_str("var a = 1; var b; a"),
       njs_str("1") },
 


More information about the nginx-devel mailing list