From b2ed3b63b35c06da32dce2052547cb4ac1ef41e7 Mon Sep 17 00:00:00 2001 From: George Roman Date: Sat, 17 Oct 2020 11:14:44 +0300 Subject: [PATCH] Fix BigInt.toString radix checks --- boa/src/builtins/bigint/mod.rs | 2 +- boa/src/builtins/bigint/tests.rs | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/boa/src/builtins/bigint/mod.rs b/boa/src/builtins/bigint/mod.rs index 82d2c629034..2ad5f610145 100644 --- a/boa/src/builtins/bigint/mod.rs +++ b/boa/src/builtins/bigint/mod.rs @@ -140,7 +140,7 @@ impl BigInt { } else { 10 }; - if radix < 2 && radix > 36 { + if radix < 2 || radix > 36 { return ctx .throw_range_error("radix must be an integer at least 2 and no greater than 36"); } diff --git a/boa/src/builtins/bigint/tests.rs b/boa/src/builtins/bigint/tests.rs index 0fdf2e52df8..210275a9140 100644 --- a/boa/src/builtins/bigint/tests.rs +++ b/boa/src/builtins/bigint/tests.rs @@ -212,6 +212,15 @@ fn to_string() { assert_eq!(forward(&mut engine, "1000n.toString(36)"), "\"rs\""); } +#[test] +fn to_string_invalid_radix() { + let mut engine = Context::new(); + + assert_throws(&mut engine, "10n.toString(null)", "RangeError"); + assert_throws(&mut engine, "10n.toString(-1)", "RangeError"); + assert_throws(&mut engine, "10n.toString(37)", "RangeError"); +} + #[test] fn as_int_n() { let mut engine = Context::new();