[njs] Fixed String.prototype.split() for UTF8-invalid byte strings.

Dmitry Volyntsev xeioex at nginx.com
Fri May 17 18:17:57 UTC 2019


details:   https://hg.nginx.org/njs/rev/e22397fd709a
branches:  
changeset: 969:e22397fd709a
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Fri May 17 21:16:31 2019 +0300
description:
Fixed String.prototype.split() for UTF8-invalid byte strings.

This closes #161 issue on Github.

diffstat:

 njs/njs_string.c |  8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diffs (32 lines):

diff -r 9af8e1b5f3c1 -r e22397fd709a njs/njs_string.c
--- a/njs/njs_string.c	Fri May 17 17:52:30 2019 +0300
+++ b/njs/njs_string.c	Fri May 17 21:16:31 2019 +0300
@@ -2757,7 +2757,7 @@ njs_string_match_multiple(njs_vm_t *vm, 
 
 
 /*
- * 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;
                 }
 


More information about the nginx-devel mailing list