Welcome! Log In Create A New Profile

Advanced

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

Alexander Borisov
July 16, 2019 10:34AM
details: https://hg.nginx.org/njs/rev/84eda5521a44
branches:
changeset: 1055:84eda5521a44
user: Alexander Borisov <alexander.borisov@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") },

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

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

Alexander Borisov 241 July 16, 2019 10:34AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 305
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready