[njs] Fixed parseInt() leading white space ignoring.

Andrey Zelenkov zelenkov at nginx.com
Wed May 31 17:37:57 UTC 2017


details:   http://hg.nginx.org/njs/rev/559d256dd65b
branches:  
changeset: 349:559d256dd65b
user:      Andrey Zelenkov <zelenkov at nginx.com>
date:      Wed May 31 20:36:01 2017 +0300
description:
Fixed parseInt() leading white space ignoring.

diffstat:

 njs/njs_number.c         |  3 +--
 njs/test/njs_unit_test.c |  3 +++
 2 files changed, 4 insertions(+), 2 deletions(-)

diffs (28 lines):

diff -r b592f24c9ac6 -r 559d256dd65b njs/njs_number.c
--- a/njs/njs_number.c	Wed May 31 20:25:44 2017 +0300
+++ b/njs/njs_number.c	Wed May 31 20:36:01 2017 +0300
@@ -709,10 +709,9 @@ njs_number_parse_int(njs_vm_t *vm, njs_v
     if (nargs > 1) {
         (void) njs_string_prop(&string, &args[1]);
 
-        p = string.start;
         end = string.start + string.size;
 
-        while (p < end) {
+        for (p = string.start; p < end; p++) {
             if (*p != ' ') {
                 goto found;
             }
diff -r b592f24c9ac6 -r 559d256dd65b njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c	Wed May 31 20:25:44 2017 +0300
+++ b/njs/test/njs_unit_test.c	Wed May 31 20:36:01 2017 +0300
@@ -7150,6 +7150,9 @@ static njs_unit_test_t  njs_test[] =
     { nxt_string("parseInt('0XaBc', 0)"),
       nxt_string("2748") },
 
+    { nxt_string("parseInt(' 123')"),
+      nxt_string("123") },
+
     { nxt_string("parseInt('1010', 2)"),
       nxt_string("10") },
 


More information about the nginx-devel mailing list