]> git.kaiwu.me - njs.git/commitdiff
Fixed String.prototype.split() for UTF8-invalid byte strings.
authorDmitry Volyntsev <xeioex@nginx.com>
Fri, 17 May 2019 18:16:31 +0000 (21:16 +0300)
committerDmitry Volyntsev <xeioex@nginx.com>
Fri, 17 May 2019 18:16:31 +0000 (21:16 +0300)
This closes #161 issue on Github.

njs/njs_string.c

index ae3f97187612bdc0504099376d5990a4c0f54431..a3a3d74f7ad29e039e3425c848fe7bfbddcd592f 100644 (file)
@@ -2757,7 +2757,7 @@ njs_string_match_multiple(njs_vm_t *vm, njs_value_t *args,
 
 
 /*
- * String.split([string|regexp[, limit]])
+ * String.prototype.split([string|regexp[, limit]])
  */
 
 static njs_ret_t
@@ -2838,7 +2838,8 @@ found:
 
                 /* Empty split string. */
                 if (p == next) {
-                    p = nxt_utf8_next(p, end);
+                    p = (utf8 != NJS_STRING_BYTE) ? nxt_utf8_next(p, end)
+                                                  : p + 1;
                     next = p;
                 }
 
@@ -2885,7 +2886,8 @@ found:
 
                 /* Empty split regexp. */
                 if (p == next) {
-                    p = nxt_utf8_next(p, end);
+                    p = (utf8 != NJS_STRING_BYTE) ? nxt_utf8_next(p, end)
+                                                  : p + 1;
                     next = p;
                 }