]> git.kaiwu.me - njs.git/commitdiff
Fixed njs_string_to_number() with additional space symbols.
authorArtem S. Povalyukhin <artem.povaluhin@gmail.com>
Fri, 3 Mar 2023 19:57:30 +0000 (22:57 +0300)
committerArtem S. Povalyukhin <artem.povaluhin@gmail.com>
Fri, 3 Mar 2023 19:57:30 +0000 (22:57 +0300)
This closes #621 issue on Github.

src/njs_string.c
src/test/njs_unit_test.c

index 84a48f1a0eb834e795a595adce87a47effa98d7b..360f758bff129c4585acde9f87ae065a783185e6 100644 (file)
@@ -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;
             }
 
index dc12f8f82234afbf7ea763d855b157700f1ad33c..3864e197afc9c43d0d255f10e77e3423115ad061 100644 (file)
@@ -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") },