Merge pull request #9800 from creative-commoners/pulls/4.7/arraylist-value-set

FIX Bug when specifying 0 in ArrayList::offsetSet
This commit is contained in:
Sam Minnée 2020-12-16 15:40:20 +13:00 committed by GitHub
commit a8d121d23f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View File

@ -844,7 +844,7 @@ class ArrayList extends ViewableData implements SS_List, Filterable, Sortable, L
*/ */
public function offsetSet($offset, $value) public function offsetSet($offset, $value)
{ {
if ($offset == null) { if ($offset === null) {
$this->items[] = $value; $this->items[] = $value;
} else { } else {
$this->items[$offset] = $value; $this->items[$offset] = $value;

View File

@ -1251,4 +1251,14 @@ class ArrayListTest extends SapphireTest
$this->assertNotEquals(range(1, $upperLimit), $list->toArray()); $this->assertNotEquals(range(1, $upperLimit), $list->toArray());
} }
public function testOffsetSet()
{
$list = new ArrayList(['first value', 'second value']);
$this->assertSame(2, $list->count());
$list->offsetSet(0, 'new value');
$this->assertSame(2, $list->count());
$this->assertSame('new value', $list->offsetGet(0));
$this->assertSame('second value', $list->offsetGet(1));
}
} }