diff --git a/jerry-core/parser/js/lexer.cpp b/jerry-core/parser/js/lexer.cpp index 78f7dc8f3..613aa1c36 100644 --- a/jerry-core/parser/js/lexer.cpp +++ b/jerry-core/parser/js/lexer.cpp @@ -1155,6 +1155,12 @@ lexer_parse_regexp (void) return result; } /* lexer_parse_regexp */ +/** + * Parse a comment + * + * @return true if newline was met during parsing + * false - otherwise + */ static bool lexer_parse_comment (void) { @@ -1170,7 +1176,7 @@ lexer_parse_comment (void) consume_char (); consume_char (); - while (true) + while (!lit_utf8_iterator_is_eos (&src_iter)) { c = LA (0); @@ -1180,10 +1186,6 @@ lexer_parse_comment (void) { return true; } - else if (c == LIT_CHAR_NULL) - { - return false; - } } else { @@ -1199,14 +1201,17 @@ lexer_parse_comment (void) { was_newlines = true; } - else if (c == LIT_CHAR_NULL) - { - PARSE_ERROR (JSP_EARLY_ERROR_SYNTAX, "Unclosed multiline comment", lit_utf8_iterator_get_pos (&src_iter)); - } } consume_char (); } + + if (multiline) + { + PARSE_ERROR (JSP_EARLY_ERROR_SYNTAX, "Unclosed multiline comment", lit_utf8_iterator_get_pos (&src_iter)); + } + + return false; } /* lexer_parse_comment */ /** diff --git a/tests/jerry/zero-character.js b/tests/jerry/zero-character.js new file mode 100644 index 000000000..478bf4ea0 --- /dev/null +++ b/tests/jerry/zero-character.js @@ -0,0 +1,20 @@ +// Copyright 2015 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +try { + eval("/*var " + String.fromCharCode(0) + "xx = 1*/"); +} +catch (e) { + assert (false); +}