From 4879777df084ff42681afe3513a26b6a98e110ee Mon Sep 17 00:00:00 2001 From: Andrey Zelenkov Date: Wed, 31 May 2017 20:25:44 +0300 Subject: [PATCH] Fixed parseInt() zero radix parsing. --- njs/njs_number.c | 16 ++++++++++------ njs/test/njs_unit_test.c | 6 ++++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/njs/njs_number.c b/njs/njs_number.c index 6223b76d..1d19d37e 100644 --- a/njs/njs_number.c +++ b/njs/njs_number.c @@ -733,19 +733,23 @@ njs_number_parse_int(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, } test_prefix = (end - p > 1); + radix = 0; if (nargs > 2) { radix = args[2].data.u.number; - if (radix < 2 || radix > 36) { - goto done; - } + if (radix != 0) { + if (radix < 2 || radix > 36) { + goto done; + } - if (radix != 16) { - test_prefix = 0; + if (radix != 16) { + test_prefix = 0; + } } + } - } else { + if (radix == 0) { radix = 10; } diff --git a/njs/test/njs_unit_test.c b/njs/test/njs_unit_test.c index b339d775..fe188837 100644 --- a/njs/test/njs_unit_test.c +++ b/njs/test/njs_unit_test.c @@ -7144,6 +7144,12 @@ static njs_unit_test_t njs_test[] = { nxt_string("parseInt('12345abc')"), nxt_string("12345") }, + { nxt_string("parseInt('123', 0)"), + nxt_string("123") }, + + { nxt_string("parseInt('0XaBc', 0)"), + nxt_string("2748") }, + { nxt_string("parseInt('1010', 2)"), nxt_string("10") }, -- 2.47.3