Fix zero position bugs in array methods.

This commit is contained in:
Stephen Chung 2021-04-19 15:11:03 +08:00
parent 1145c5a4c0
commit c5e716e71f
2 changed files with 7 additions and 2 deletions

View File

@ -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
----------------

View File

@ -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)