Welcome! Log In Create A New Profile

Advanced

[njs] Fixed RegExp literal parsing.

Dmitry Volyntsev
March 05, 2019 11:56AM
details: https://hg.nginx.org/njs/rev/acc5fc4be35b
branches:
changeset: 817:acc5fc4be35b
user: Dmitry Volyntsev <xeioex@nginx.com>
date: Tue Mar 05 19:54:23 2019 +0300
description:
Fixed RegExp literal parsing.

diffstat:

njs/njs_regexp.c | 11 ++++++-----
njs/test/njs_unit_test.c | 15 +++++++++++++++
2 files changed, 21 insertions(+), 5 deletions(-)

diffs (55 lines):

diff -r 109697757094 -r acc5fc4be35b njs/njs_regexp.c
--- a/njs/njs_regexp.c Tue Mar 05 08:32:54 2019 +0800
+++ b/njs/njs_regexp.c Tue Mar 05 19:54:23 2019 +0300
@@ -138,7 +138,7 @@ njs_regexp_create(njs_vm_t *vm, njs_valu
njs_token_t
njs_regexp_literal(njs_vm_t *vm, njs_parser_t *parser, njs_value_t *value)
{
- u_char *p;
+ u_char *p, c;
njs_lexer_t *lexer;
njs_regexp_flags_t flags;
njs_regexp_pattern_t *pattern;
@@ -147,12 +147,13 @@ njs_regexp_literal(njs_vm_t *vm, njs_par

for (p = lexer->start; p < lexer->end; p++) {

- if (*p == '\\') {
- p++;
- continue;
+ c = *p;
+
+ if (c == '\n' || c == '\r') {
+ break;
}

- if (*p == '/') {
+ if (c == '/' && !(p > lexer->start && p[-1] == '\\')) {
lexer->text.start = lexer->start;
lexer->text.length = p - lexer->text.start;
p++;
diff -r 109697757094 -r acc5fc4be35b njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c Tue Mar 05 08:32:54 2019 +0800
+++ b/njs/test/njs_unit_test.c Tue Mar 05 19:54:23 2019 +0300
@@ -6526,6 +6526,21 @@ static njs_unit_test_t njs_test[] =
{ nxt_string("/"),
nxt_string("SyntaxError: Unterminated RegExp \"/\" in 1") },

+ { nxt_string("/a\n/"),
+ nxt_string("SyntaxError: Unterminated RegExp \"/a\" in 1") },
+
+ { nxt_string("/a\r/"),
+ nxt_string("SyntaxError: Unterminated RegExp \"/a\" in 1") },
+
+ { nxt_string("/a\\q/"),
+ nxt_string("/a\\q/") },
+
+ { nxt_string("/a\\q/.test('a\\q')"),
+ nxt_string("true") },
+
+ { nxt_string("/(\\.(?!com|org)|\\/)/.test('ah.info')"),
+ nxt_string("true") },
+
{ nxt_string("/(/.test('')"),
nxt_string("SyntaxError: pcre_compile(\"(\") failed: missing ) in 1") },

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Fixed RegExp literal parsing.

Dmitry Volyntsev 48 March 05, 2019 11:56AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 101
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready