]> git.kaiwu.me - njs.git/commitdiff
Fixed String.prototype.substring() with empty substring.
authorAlexander Borisov <alexander.borisov@nginx.com>
Tue, 16 Jul 2019 14:32:12 +0000 (17:32 +0300)
committerAlexander Borisov <alexander.borisov@nginx.com>
Tue, 16 Jul 2019 14:32:12 +0000 (17:32 +0300)
njs/njs_string.c
njs/test/njs_unit_test.c

index e4ddd1281b55fa18ce7405d234fe59b5b33a12e2..f2b65740f36ef3c2f9beacca4f6fa360588b55b1 100644 (file)
@@ -1357,10 +1357,10 @@ njs_string_slice_string_prop(njs_string_prop_t *dst,
         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;
index 860ab5a966360cdd8c77bef1d2a1f8a9548dd502..94be56d71b4605fd4f514c1899a4545fe4e4e1f8 100644 (file)
@@ -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") },