Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All package updates & migration steps will be listed in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [4.3.1] - 2025-01-06
### Fixed
- `ReadOnlyListContainer` now throws `IndexOutOfRangeException` when accessed out of range.

## [4.3.0] - 2024-11-22
### Added
- `Warning` and `Error` severity levels for `ValidatorError`
Expand Down
10 changes: 9 additions & 1 deletion Runtime/Types/ReadOnlyListContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@ public ReadOnlyListContainer(Func<int> countFunc, Func<int, T> getterFunc)
_getterFunc = getterFunc;
}

public T this[int index] => _getterFunc(index);
public T this[int index]
{
get
{
if (index < 0 || index >= Count)
throw new IndexOutOfRangeException();
return _getterFunc(index);
}
}

public int Count
{
Expand Down
17 changes: 17 additions & 0 deletions Tests/Runtime/Types/ReadOnlyListContainerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,23 @@ public void ReadingValues()
_countFunc.Received(1);
}

[Test]
public void ReadingOutOfBounds()
{
int length = 2;
var container = new ReadOnlyListContainer<int>(() => length, x => 0);

// trying to access outside of the length throws an exception
Assert.Throws<IndexOutOfRangeException>(() => {
_ = container[length];
});

// trying to access outside of the length throws an exception
Assert.Throws<IndexOutOfRangeException>(() => {
_ = container[-1];
});
}

[Test]
public void Enumerator()
{
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "com.pocketgems.scriptableobject.flatbuffer",
"version": "4.3.0",
"version": "4.3.1",
"displayName": "Scriptable Object - FlatBuffer",
"description": "Seamless syncing between Scriptable Objects and CSVs. Scriptable Object data built to Google FlatBuffers for optimal runtime loading & access.",
"unity": "2021.3",
Expand Down
Loading