Welcome! Log In Create A New Profile

Advanced

[njs] Improved String.prototype.toString() for ordinary strings.

Dmitry Volyntsev
July 24, 2020 12:26PM
details: https://hg.nginx.org/njs/rev/354318f9b00f
branches:
changeset: 1479:354318f9b00f
user: Dmitry Volyntsev <xeioex@nginx.com>
date: Fri Jul 24 14:02:04 2020 +0000
description:
Improved String.prototype.toString() for ordinary strings.

Allowing converting all strings to encodings 'hex', 'base64', 'base64url'.

diffstat:

src/njs_string.c | 9 ++-------
src/test/njs_unit_test.c | 3 ---
2 files changed, 2 insertions(+), 10 deletions(-)

diffs (40 lines):

diff -r 78f0887e5aa6 -r 354318f9b00f src/njs_string.c
--- a/src/njs_string.c Thu Jul 23 13:24:10 2020 +0300
+++ b/src/njs_string.c Fri Jul 24 14:02:04 2020 +0000
@@ -738,9 +738,9 @@ njs_string_prototype_value_of(njs_vm_t *


/*
- * String.toString([encoding]).
+ * String.prototype.toString([encoding]).
* Returns the string as is if no additional argument is provided,
- * otherwise converts a byte string into an encoded string: hex, base64,
+ * otherwise converts a string into an encoded string: hex, base64,
* base64url.
*/

@@ -771,11 +771,6 @@ njs_string_prototype_to_string(njs_vm_t

(void) njs_string_prop(&string, &value);

- if (njs_slow_path(string.length != 0)) {
- njs_type_error(vm, "argument must be a byte string");
- return NJS_ERROR;
- }
-
njs_string_get(&args[1], &enc);

str.length = string.size;
diff -r 78f0887e5aa6 -r 354318f9b00f src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c Thu Jul 23 13:24:10 2020 +0300
+++ b/src/test/njs_unit_test.c Fri Jul 24 14:02:04 2020 +0000
@@ -895,9 +895,6 @@ static njs_unit_test_t njs_test[] =
{ njs_str("'A'.toString()"),
njs_str("A") },

- { njs_str("'A'.toString('hex')"),
- njs_str("TypeError: argument must be a byte string") },
-
{ njs_str("'A'.toBytes().toString('latin1')"),
njs_str("TypeError: Unknown encoding: \"latin1\"") },

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

[njs] Improved String.prototype.toString() for ordinary strings.

Dmitry Volyntsev 373 July 24, 2020 12:26PM



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

Online Users

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