]> git.kaiwu.me - njs.git/commitdiff
Fixed String.prototype.split() for unicode strings.
authorDmitry Volyntsev <xeioex@nginx.com>
Thu, 14 Feb 2019 18:19:51 +0000 (21:19 +0300)
committerDmitry Volyntsev <xeioex@nginx.com>
Thu, 14 Feb 2019 18:19:51 +0000 (21:19 +0300)
This closes #95 issue on Github.

njs/njs_string.c
njs/test/njs_unit_test.c

index 8b49d4d5e2c1f4085601eb366dd88a934033af5d..06b43d7ee5638f206cea1f6efef900bd7492d661 100644 (file)
@@ -2798,8 +2798,8 @@ njs_string_prototype_split(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
 
                 /* 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, njs_value_t *args, nxt_uint_t nargs,
 
                 /* Empty split regexp. */
                 if (p == next) {
-                    p++;
-                    next++;
+                    p = nxt_utf8_next(p, end);
+                    next = p;
                 }
 
                 size = p - start;
index e8b0eb108c1ab7f2192de82a7fec6e17e9ae7250..2672d85fec70ea589a83ebb245d00e52fa8e997e 100644 (file)
@@ -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(",") },