[njs] Fixed parsing multiline comments.

Dmitry Volyntsev xeioex at nginx.com
Tue Jan 29 15:15:21 UTC 2019


details:   https://hg.nginx.org/njs/rev/348a34597bab
branches:  
changeset: 741:348a34597bab
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Tue Jan 29 18:15:03 2019 +0300
description:
Fixed parsing multiline comments.

diffstat:

 njs/njs_lexer.c                 |   6 ++----
 njs/test/njs_interactive_test.c |  17 +++++++++++++++++
 njs/test/njs_unit_test.c        |   3 +++
 3 files changed, 22 insertions(+), 4 deletions(-)

diffs (56 lines):

diff -r ef39ae753b9e -r 348a34597bab njs/njs_lexer.c
--- a/njs/njs_lexer.c	Tue Jan 29 16:49:36 2019 +0300
+++ b/njs/njs_lexer.c	Tue Jan 29 18:15:03 2019 +0300
@@ -704,10 +704,8 @@ njs_lexer_division(njs_lexer_t *lexer, n
                 }
 
                 if (*p == '*') {
-                    p++;
-
-                    if (p < lexer->end && *p == '/') {
-                        lexer->start = p + 1;
+                    if (p + 1 < lexer->end && p[1] == '/') {
+                        lexer->start = p + 2;
                         return NJS_TOKEN_AGAIN;
                     }
                 }
diff -r ef39ae753b9e -r 348a34597bab njs/test/njs_interactive_test.c
--- a/njs/test/njs_interactive_test.c	Tue Jan 29 16:49:36 2019 +0300
+++ b/njs/test/njs_interactive_test.c	Tue Jan 29 18:15:03 2019 +0300
@@ -233,6 +233,23 @@ static njs_interactive_test_t  njs_test[
       nxt_string("TypeError: Cannot convert object to primitive value\n"
                  "    at main (native)\n") },
 
+    /* line numbers */
+
+    { nxt_string("/**/(function(){throw Error();})()" ENTER),
+      nxt_string("Error\n"
+                 "    at anonymous (:1)\n"
+                 "    at main (native)\n") },
+
+    { nxt_string("/***/(function(){throw Error();})()" ENTER),
+      nxt_string("Error\n"
+                 "    at anonymous (:1)\n"
+                 "    at main (native)\n") },
+
+    { nxt_string("/*\n**/(function(){throw Error();})()" ENTER),
+      nxt_string("Error\n"
+                 "    at anonymous (:2)\n"
+                 "    at main (native)\n") },
+
 };
 
 
diff -r ef39ae753b9e -r 348a34597bab njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c	Tue Jan 29 16:49:36 2019 +0300
+++ b/njs/test/njs_unit_test.c	Tue Jan 29 18:15:03 2019 +0300
@@ -28,6 +28,9 @@ static njs_unit_test_t  njs_test[] =
     { nxt_string("1}"),
       nxt_string("SyntaxError: Unexpected token \"}\" in 1") },
 
+    { nxt_string("/***/1/*\n**/"),
+      nxt_string("1") },
+
     /* Variable declarations. */
 
     { nxt_string("var x"),


More information about the nginx-devel mailing list