details: http://hg.nginx.org/njs/rev/ab1f67b69707 branches: changeset: 453:ab1f67b69707 user: Igor Sysoev <i...@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