[njs] Fixed String.prototype.match() for byte strings with regex arg.

Alexander Borisov alexander.borisov at nginx.com
Tue Jul 16 14:32:51 UTC 2019


details:   https://hg.nginx.org/njs/rev/8ac396f1a20c
branches:  
changeset: 1053:8ac396f1a20c
user:      Alexander Borisov <alexander.borisov at nginx.com>
date:      Tue Jul 16 17:32:11 2019 +0300
description:
Fixed String.prototype.match() for byte strings with regex arg.

diffstat:

 njs/njs_string.c         |  3 ++-
 njs/test/njs_unit_test.c |  3 +++
 2 files changed, 5 insertions(+), 1 deletions(-)

diffs (26 lines):

diff -r 9e6098cb3b2e -r 8ac396f1a20c njs/njs_string.c
--- a/njs/njs_string.c	Tue Jul 16 17:32:10 2019 +0300
+++ b/njs/njs_string.c	Tue Jul 16 17:32:11 2019 +0300
@@ -2757,7 +2757,8 @@ njs_string_match_multiple(njs_vm_t *vm, 
 
             if (captures[1] == 0) {
                 if (start < end) {
-                    p = nxt_utf8_next(start, end);
+                    p = (utf8 != NJS_STRING_BYTE) ? nxt_utf8_next(start, end)
+                                                  : start + 1;
                     string.size = end - p;
 
                 } else {
diff -r 9e6098cb3b2e -r 8ac396f1a20c njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c	Tue Jul 16 17:32:10 2019 +0300
+++ b/njs/test/njs_unit_test.c	Tue Jul 16 17:32:11 2019 +0300
@@ -5832,6 +5832,9 @@ static njs_unit_test_t  njs_test[] =
                  "a +' '+ a.length"),
       nxt_string("αα 4") },
 
+    { nxt_string("typeof String.bytesFrom(Array(15).fill(0xE3)).match(/^/g)"),
+      nxt_string("object") },
+
     { nxt_string("'abc'.split()"),
       nxt_string("abc") },
 


More information about the nginx-devel mailing list