[njs] Fixed Regexp.prototype.exec() for unicode only regexps.

Dmitry Volyntsev xeioex at nginx.com
Wed Apr 17 18:12:43 UTC 2019


details:   https://hg.nginx.org/njs/rev/9c67f7d03672
branches:  
changeset: 900:9c67f7d03672
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Wed Apr 17 21:12:21 2019 +0300
description:
Fixed Regexp.prototype.exec() for unicode only regexps.

This closes #138 issue on Github.

diffstat:

 njs/njs_regexp.c         |  8 +++++---
 njs/test/njs_unit_test.c |  3 +++
 2 files changed, 8 insertions(+), 3 deletions(-)

diffs (51 lines):

diff -r 39790a9d9b58 -r 9c67f7d03672 njs/njs_regexp.c
--- a/njs/njs_regexp.c	Wed Apr 17 18:43:13 2019 +0300
+++ b/njs/njs_regexp.c	Wed Apr 17 21:12:21 2019 +0300
@@ -334,6 +334,8 @@ njs_regexp_pattern_create(njs_vm_t *vm, 
             goto fail;
         }
 
+        pattern->ncaptures = ret;
+
     } else if (ret != NXT_DECLINED) {
         goto fail;
     }
@@ -633,14 +635,14 @@ njs_regexp_prototype_exec(njs_vm_t *vm, 
 {
     njs_ret_t               ret;
     njs_utf8_t              utf8;
-    njs_value_t             *value;
     njs_regexp_t            *regexp;
     njs_string_prop_t       string;
     njs_regexp_utf8_t       type;
+    const njs_value_t       *value;
     njs_regexp_pattern_t    *pattern;
     nxt_regex_match_data_t  *match_data;
 
-    if (!njs_is_regexp(&args[0])) {
+    if (!njs_is_regexp(njs_arg(args, nargs, 0))) {
         njs_type_error(vm, "\"this\" argument is not a regexp");
         return NXT_ERROR;
     }
@@ -649,7 +651,7 @@ njs_regexp_prototype_exec(njs_vm_t *vm, 
         value = &args[1];
 
     } else {
-        value = (njs_value_t *) &njs_string_undefined;
+        value = &njs_string_undefined;
     }
 
     regexp = args[0].data.u.regexp;
diff -r 39790a9d9b58 -r 9c67f7d03672 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c	Wed Apr 17 18:43:13 2019 +0300
+++ b/njs/test/njs_unit_test.c	Wed Apr 17 21:12:21 2019 +0300
@@ -11980,6 +11980,9 @@ static njs_unit_test_t  njs_regexp_test[
 
     { nxt_string("RegExp('[\\\\u0430-\\\\u044f]+').test('тест')"),
       nxt_string("true") },
+
+    { nxt_string("RegExp('[\\\\u0430-\\\\u044f]+').exec('тест')[0]"),
+      nxt_string("тест") },
 };
 
 


More information about the nginx-devel mailing list