Welcome! Log In Create A New Profile

Advanced

[njs] Fixed String.prototype.toUTF8() function.

February 28, 2018 08:22AM
details: http://hg.nginx.org/njs/rev/ab1f67b69707
branches:
changeset: 453:ab1f67b69707
user: Igor Sysoev <igor@sysoev.ru>
date: Wed Feb 28 16:20:11 2018 +0300
description:
Fixed String.prototype.toUTF8() function.

A byte string returned by String.prototype.toUTF8() had length equal
to its size so the string can be processed later as an ASCII string.

diffstat:

njs/njs_string.c | 5 +++++
njs/test/njs_unit_test.c | 9 +++++++++
2 files changed, 14 insertions(+), 0 deletions(-)

diffs (34 lines):

diff -r 0f1c3efcd894 -r ab1f67b69707 njs/njs_string.c
--- a/njs/njs_string.c Tue Feb 27 14:11:00 2018 +0300
+++ b/njs/njs_string.c Wed Feb 28 16:20:11 2018 +0300
@@ -1051,6 +1051,11 @@ njs_string_slice(njs_vm_t *vm, njs_value
start += slice->start;
size = slice->length;

+ if (string->length == 0) {
+ /* Byte string. */
+ length = 0;
+ }
+
} else {
/* UTF-8 string. */
end = start + string->size;
diff -r 0f1c3efcd894 -r ab1f67b69707 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c Tue Feb 27 14:11:00 2018 +0300
+++ b/njs/test/njs_unit_test.c Wed Feb 28 16:20:11 2018 +0300
@@ -3529,6 +3529,15 @@ static njs_unit_test_t njs_test[] =
{ nxt_string("'α'.toUTF8()[0]"),
nxt_string("\xCE") },

+ { nxt_string("/^\\x80$/.test('\\x80'.toBytes())"),
+ nxt_string("true") },
+
+ { nxt_string("/^\\xC2\\x80$/.test('\\x80'.toUTF8())"),
+ nxt_string("true") },
+
+ { nxt_string("'α'.toUTF8().toBytes()"),
+ nxt_string("α") },
+
{ nxt_string("var a = 'a'.toBytes() + 'α'; a + a.length"),
nxt_string("aα3") },

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

[njs] Fixed String.prototype.toUTF8() function.

Igor Sysoev 617 February 28, 2018 08:22AM



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

Online Users

Guests: 55
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready