From: Artem S. Povalyukhin Date: Fri, 3 Mar 2023 19:57:30 +0000 (+0300) Subject: Fixed njs_string_to_number() with additional space symbols. X-Git-Tag: 0.7.11~5 X-Git-Url: http://git.kaiwu.me/postgresql/log/contrib/postgres_fdw/static/gitweb.js?a=commitdiff_plain;h=37f7e812aacf0f65e2dd9f97d93f7c78d4dd375b;p=njs.git Fixed njs_string_to_number() with additional space symbols. This closes #621 issue on Github. --- diff --git a/src/njs_string.c b/src/njs_string.c index 84a48f1a..360f758b 100644 --- a/src/njs_string.c +++ b/src/njs_string.c @@ -3974,7 +3974,7 @@ njs_string_to_number(const njs_value_t *value, njs_bool_t parse_float) if (!parse_float) { while (p < end) { - if (*p != ' ' && *p != '\t') { + if (!njs_is_whitespace(*p)) { return NAN; } diff --git a/src/test/njs_unit_test.c b/src/test/njs_unit_test.c index dc12f8f8..3864e197 100644 --- a/src/test/njs_unit_test.c +++ b/src/test/njs_unit_test.c @@ -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") },