[njs] A line number in error messages was incorrect if a script

Igor Sysoev igor at sysoev.ru
Fri Jul 22 12:04:50 UTC 2016


details:   http://hg.nginx.org/njs/rev/eae6c48ff5c1
branches:  
changeset: 130:eae6c48ff5c1
user:      Igor Sysoev <igor at sysoev.ru>
date:      Thu Jul 21 21:42:58 2016 +0300
description:
A line number in error messages was incorrect if a script
has comments.

diffstat:

 njs/njs_lexer.c          |  8 +++++++-
 njs/test/njs_unit_test.c |  6 ++++++
 2 files changed, 13 insertions(+), 1 deletions(-)

diffs (42 lines):

diff -r 41689f60372a -r eae6c48ff5c1 njs/njs_lexer.c
--- a/njs/njs_lexer.c	Thu Jul 21 21:37:46 2016 +0300
+++ b/njs/njs_lexer.c	Thu Jul 21 21:42:58 2016 +0300
@@ -636,8 +636,9 @@ njs_lexer_division(njs_lexer_t *lexer, n
 
             for (p = lexer->start; p < lexer->end; p++) {
 
-                if (*p == '\r' || *p == '\n') {
+                if (*p == '\n') {
                     lexer->start = p + 1;
+                    lexer->line++;
                     return NJS_TOKEN_LINE_END;
                 }
             }
@@ -647,6 +648,11 @@ njs_lexer_division(njs_lexer_t *lexer, n
 
             for (p = lexer->start; p < lexer->end; p++) {
 
+                if (*p == '\n') {
+                    lexer->line++;
+                    continue;
+                }
+
                 if (*p == '*') {
                     p++;
 
diff -r 41689f60372a -r eae6c48ff5c1 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c	Thu Jul 21 21:37:46 2016 +0300
+++ b/njs/test/njs_unit_test.c	Thu Jul 21 21:42:58 2016 +0300
@@ -52,6 +52,12 @@ static njs_unit_test_t  njs_test[] =
     { nxt_string("var + a"),
       nxt_string("SyntaxError: Unexpected token \"+\" in 1") },
 
+    { nxt_string("//\r\n; var + a"),
+      nxt_string("SyntaxError: Unexpected token \"+\" in 2") },
+
+    { nxt_string("/*\n*/; var + a"),
+      nxt_string("SyntaxError: Unexpected token \"+\" in 2") },
+
     { nxt_string("var \n a \n = 1; a"),
       nxt_string("1") },
 



More information about the nginx-devel mailing list