From c5e716e71f2c6cda8991a5a46104eb959fd2f59e Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Mon, 19 Apr 2021 15:11:03 +0800 Subject: [PATCH] Fix zero position bugs in array methods. --- CHANGELOG.md | 5 +++++ src/packages/array_basic.rs | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ede0882..142f71ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ Version 0.20.1 This version enables functions to access constants declared at global level via the special `global` module. +Bug fixes +--------- + +* Fixed bug when position is zero in `insert` and `split_at` methods for arrays. + Breaking changes ---------------- diff --git a/src/packages/array_basic.rs b/src/packages/array_basic.rs index 0751428c..f17a62aa 100644 --- a/src/packages/array_basic.rs +++ b/src/packages/array_basic.rs @@ -35,7 +35,7 @@ mod array_functions { array } pub fn insert(array: &mut Array, position: INT, item: Dynamic) { - if position <= 0 { + if position < 0 { if let Some(n) = position.checked_abs() { if n as usize > array.len() { array.insert(0, item); @@ -174,7 +174,7 @@ mod array_functions { } #[rhai_fn(name = "split")] pub fn split_at(array: &mut Array, start: INT) -> Array { - if start <= 0 { + if start < 0 { if let Some(n) = start.checked_abs() { if n as usize > array.len() { mem::take(array)