From: Dmitry Volyntsev Date: Tue, 29 Jan 2019 15:15:03 +0000 (+0300) Subject: Fixed parsing multiline comments. X-Git-Tag: 0.2.8~61 X-Git-Url: http://www.kaiwu.me/postgresql/commit/?a=commitdiff_plain;h=b61fbd65a2b565af4495f67791e31767c1c15833;p=njs.git Fixed parsing multiline comments. --- diff --git a/njs/njs_lexer.c b/njs/njs_lexer.c index 3ea7495d..adb64396 100644 --- a/njs/njs_lexer.c +++ b/njs/njs_lexer.c @@ -704,10 +704,8 @@ njs_lexer_division(njs_lexer_t *lexer, njs_token_t token) } 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 --git a/njs/test/njs_interactive_test.c b/njs/test/njs_interactive_test.c index 94d2a237..4cdd4879 100644 --- a/njs/test/njs_interactive_test.c +++ b/njs/test/njs_interactive_test.c @@ -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 --git a/njs/test/njs_unit_test.c b/njs/test/njs_unit_test.c index 046e6e84..a9670817 100644 --- a/njs/test/njs_unit_test.c +++ b/njs/test/njs_unit_test.c @@ -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"),