[njs] Fixed String.prototype.split() for unicode strings.

Dmitry Volyntsev xeioex at nginx.com
Fri Feb 15 15:51:43 UTC 2019


details:   https://hg.nginx.org/njs/rev/8c422e42448e
branches:  
changeset: 781:8c422e42448e
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Thu Feb 14 21:19:51 2019 +0300
description:
Fixed String.prototype.split() for unicode strings.

This closes #95 issue on Github.

diffstat:

 njs/njs_string.c         |   8 ++++----
 njs/test/njs_unit_test.c |  12 ++++++++++++
 2 files changed, 16 insertions(+), 4 deletions(-)

diffs (47 lines):

diff -r e1bfc7be7c55 -r 8c422e42448e njs/njs_string.c
--- a/njs/njs_string.c	Thu Feb 14 21:19:51 2019 +0300
+++ b/njs/njs_string.c	Thu Feb 14 21:19:51 2019 +0300
@@ -2798,8 +2798,8 @@ njs_string_prototype_split(njs_vm_t *vm,
 
                 /* Empty split string. */
                 if (p == next) {
-                    p++;
-                    next++;
+                    p = nxt_utf8_next(p, end);
+                    next = p;
                 }
 
                 size = p - start;
@@ -2845,8 +2845,8 @@ njs_string_prototype_split(njs_vm_t *vm,
 
                 /* Empty split regexp. */
                 if (p == next) {
-                    p++;
-                    next++;
+                    p = nxt_utf8_next(p, end);
+                    next = p;
                 }
 
                 size = p - start;
diff -r e1bfc7be7c55 -r 8c422e42448e njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c	Thu Feb 14 21:19:51 2019 +0300
+++ b/njs/test/njs_unit_test.c	Thu Feb 14 21:19:51 2019 +0300
@@ -5078,6 +5078,18 @@ static njs_unit_test_t  njs_test[] =
     { nxt_string("'abc'.split('')"),
       nxt_string("a,b,c") },
 
+    { nxt_string("'αβγ'.split('')"),
+      nxt_string("α,β,γ") },
+
+    { nxt_string("'囲碁織'.split('')"),
+      nxt_string("囲,碁,織") },
+
+    { nxt_string("'𝟘𝟙𝟚𝟛'.split('')"),
+      nxt_string("𝟘,𝟙,𝟚,𝟛") },
+
+    { nxt_string("'囲α碁α織'.split('α')"),
+      nxt_string("囲,碁,織") },
+
     { nxt_string("'abc'.split('abc')"),
       nxt_string(",") },
 


More information about the nginx-devel mailing list