Welcome! Log In Create A New Profile

Advanced

[njs] Fixed String.prototype.toBytes() for ASCII strings.

Dmitry Volyntsev
May 31, 2019 08:14AM
details: https://hg.nginx.org/njs/rev/1041e3241457
branches:
changeset: 996:1041e3241457
user: Dmitry Volyntsev <xeioex@nginx.com>
date: Fri May 31 15:11:39 2019 +0300
description:
Fixed String.prototype.toBytes() for ASCII strings.

This closes #155 issue on Github.

diffstat:

njs/njs_string.c | 2 +-
njs/test/njs_unit_test.c | 12 ++++++++++++
2 files changed, 13 insertions(+), 1 deletions(-)

diffs (34 lines):

diff -r cc9a99f09b51 -r 1041e3241457 njs/njs_string.c
--- a/njs/njs_string.c Thu May 30 16:46:26 2019 +0300
+++ b/njs/njs_string.c Fri May 31 15:11:39 2019 +0300
@@ -1048,7 +1048,7 @@ njs_string_prototype_to_bytes(njs_vm_t *

if (nxt_fast_path(p != NULL)) {

- if (string.length != 0) {
+ if (string.length != string.size) {
/* UTF-8 string. */
end = string.start + string.size;

diff -r cc9a99f09b51 -r 1041e3241457 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c Thu May 30 16:46:26 2019 +0300
+++ b/njs/test/njs_unit_test.c Fri May 31 15:11:39 2019 +0300
@@ -4644,6 +4644,18 @@ static njs_unit_test_t njs_test[] =
{ nxt_string("'A'.repeat(16).toBytes() === 'A'.repeat(16)"),
nxt_string("true") },

+ { nxt_string("'A'.repeat(38).toBytes(-5) === 'AAAAA'"),
+ nxt_string("true") },
+
+ { nxt_string("('α' + 'A'.repeat(32)).toBytes()"),
+ nxt_string("null") },
+
+ { nxt_string("('α' + 'A'.repeat(32)).toBytes(1) === 'A'.repeat(32)"),
+ nxt_string("true") },
+
+ { nxt_string("('α' + 'A'.repeat(40)).toBytes(-3,-1)"),
+ nxt_string("AA") },
+
{ nxt_string("var s = 'x'.repeat(2**10).repeat(2**14);"
"var a = Array(200).fill(s);"
"String.prototype.concat.apply(s, a.slice(1))"),
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Fixed String.prototype.toBytes() for ASCII strings.

Dmitry Volyntsev 380 May 31, 2019 08:14AM



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

Online Users

Guests: 124
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