[njs] Fixed String.prototype.substring() with empty substring.

Alexander Borisov alexander.borisov at nginx.com
Tue Jul 16 14:32:51 UTC 2019


details:   https://hg.nginx.org/njs/rev/84eda5521a44
branches:  
changeset: 1055:84eda5521a44
user:      Alexander Borisov <alexander.borisov at nginx.com>
date:      Tue Jul 16 17:32:12 2019 +0300
description:
Fixed String.prototype.substring() with empty substring.

diffstat:

 njs/njs_string.c         |  4 ++--
 njs/test/njs_unit_test.c |  3 +++
 2 files changed, 5 insertions(+), 2 deletions(-)

diffs (29 lines):

diff -r 738f2410b532 -r 84eda5521a44 njs/njs_string.c
--- a/njs/njs_string.c	Tue Jul 16 17:32:11 2019 +0300
+++ b/njs/njs_string.c	Tue Jul 16 17:32:12 2019 +0300
@@ -1357,10 +1357,10 @@ njs_string_slice_string_prop(njs_string_
         p = start;
         n = length;
 
-        do {
+        while (n != 0 && p < end) {
             p = nxt_utf8_next(p, end);
             n--;
-        } while (n != 0 && p < end);
+        }
 
         size = p - start;
         length -= n;
diff -r 738f2410b532 -r 84eda5521a44 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c	Tue Jul 16 17:32:11 2019 +0300
+++ b/njs/test/njs_unit_test.c	Tue Jul 16 17:32:12 2019 +0300
@@ -4822,6 +4822,9 @@ static njs_unit_test_t  njs_test[] =
     { nxt_string("'abcdefgh'.substring(100, 120)"),
       nxt_string("") },
 
+    { nxt_string("'α'.repeat(32).substring(32)"),
+      nxt_string("") },
+
     { nxt_string("'abcdefghijklmno'.slice(NaN, 5)"),
       nxt_string("abcde") },
 


More information about the nginx-devel mailing list