Welcome! Log In Create A New Profile

Advanced

[njs] Fixed njs_string_to_number() with additional space symbols.

Dmitry Volyntsev
March 03, 2023 09:52PM
details: https://hg.nginx.org/njs/rev/9367f3dfe0d9
branches:
changeset: 2064:9367f3dfe0d9
user: Artem S. Povalyukhin <artem.povaluhin@gmail.com>
date: Fri Mar 03 22:57:30 2023 +0300
description:
Fixed njs_string_to_number() with additional space symbols.

This closes #621 issue on Github.

diffstat:

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

diffs (25 lines):

diff -r 7ad9dd5da3fb -r 9367f3dfe0d9 src/njs_string.c
--- a/src/njs_string.c Fri Mar 03 17:49:11 2023 -0800
+++ b/src/njs_string.c Fri Mar 03 22:57:30 2023 +0300
@@ -3974,7 +3974,7 @@ njs_string_to_number(const njs_value_t *

if (!parse_float) {
while (p < end) {
- if (*p != ' ' && *p != '\t') {
+ if (!njs_is_whitespace(*p)) {
return NAN;
}

diff -r 7ad9dd5da3fb -r 9367f3dfe0d9 src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c Fri Mar 03 17:49:11 2023 -0800
+++ b/src/test/njs_unit_test.c Fri Mar 03 22:57:30 2023 +0300
@@ -13339,6 +13339,9 @@ static njs_unit_test_t njs_test[] =
{ njs_str("Number('123')"),
njs_str("123") },

+ { njs_str("['1', ' 1 ', '1\\t', '1\\n', '1\\r\\n'].reduce((a, x) => a + Number(x), 0)"),
+ njs_str("5") },
+
{ njs_str("Number('0.'+'1'.repeat(128))"),
njs_str("0.1111111111111111") },

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

[njs] Fixed njs_string_to_number() with additional space symbols.

Dmitry Volyntsev 459 March 03, 2023 09:52PM



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

Online Users

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