From 0ba577c79570435131c5c834d93bde747eba5117 Mon Sep 17 00:00:00 2001 From: Dmitry Volyntsev Date: Thu, 14 Feb 2019 21:19:51 +0300 Subject: [PATCH] Fixed String.prototype.split() for unicode strings. This closes #95 issue on Github. --- njs/njs_string.c | 8 ++++---- njs/test/njs_unit_test.c | 12 ++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/njs/njs_string.c b/njs/njs_string.c index 8b49d4d5..06b43d7e 100644 --- a/njs/njs_string.c +++ b/njs/njs_string.c @@ -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; diff --git a/njs/test/njs_unit_test.c b/njs/test/njs_unit_test.c index e8b0eb10..2672d85f 100644 --- a/njs/test/njs_unit_test.c +++ b/njs/test/njs_unit_test.c @@ -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(",") }, -- 2.47.3