From: Dmitry Volyntsev Date: Wed, 17 Apr 2019 18:12:21 +0000 (+0300) Subject: Fixed Regexp.prototype.exec() for unicode only regexps. X-Git-Url: http://git.kaiwu.me/postgresql/log/contrib/postgres_fdw/%7B@url%7D?a=commitdiff_plain;h=834901cdf520b1a911b8d26a0b0ec2159505bb54;p=njs.git Fixed Regexp.prototype.exec() for unicode only regexps. This closes #138 issue on Github. --- diff --git a/njs/njs_regexp.c b/njs/njs_regexp.c index 2a9fbe41..3fe6eec3 100644 --- a/njs/njs_regexp.c +++ b/njs/njs_regexp.c @@ -334,6 +334,8 @@ njs_regexp_pattern_create(njs_vm_t *vm, u_char *start, size_t length, 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_value_t *args, nxt_uint_t nargs, { 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, njs_value_t *args, nxt_uint_t nargs, value = &args[1]; } else { - value = (njs_value_t *) &njs_string_undefined; + value = &njs_string_undefined; } regexp = args[0].data.u.regexp; diff --git a/njs/test/njs_unit_test.c b/njs/test/njs_unit_test.c index 669dfc36..a50f40c9 100644 --- a/njs/test/njs_unit_test.c +++ b/njs/test/njs_unit_test.c @@ -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("тест") }, };