From: Dmitry Volyntsev Date: Thu, 14 Feb 2019 18:19:51 +0000 (+0300) Subject: Fixed String.prototype.split() for unicode strings. X-Git-Tag: 0.2.8~21 X-Git-Url: http://www.kaiwu.me/postgresql/commit/?a=commitdiff_plain;h=0ba577c79570435131c5c834d93bde747eba5117;p=njs.git Fixed String.prototype.split() for unicode strings. This closes #95 issue on Github. --- 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(",") },