Skip to content

Commit

Permalink
fix(Array): Fix issue with array that have numerical property key
Browse files Browse the repository at this point in the history
Fixes #571
  • Loading branch information
Belphemur committed Apr 9, 2023
1 parent 958c421 commit db7b5cb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib/ArrayInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export class ArrayInfo {

private getArrayDataAndIndexFromProperty(data: KeyValue): any {
let indexToPull = 0
let tempData = data[this.property] ?? data
let tempData = data instanceof Array ? data : data[this.property] ?? data
if (this.indicies.length > 0) {
indexToPull = +this.indicies[this.indicies.length - 1]
for (let i = 0; i < this.indicies.length - 1; i++) {
Expand Down
14 changes: 14 additions & 0 deletions test/02-jsondb.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,20 @@ describe('JsonDB', () => {
}
)

//issue #571
test(
'should have no issue with numerical property for getting data in an array',
async () => {
await db.push('/issue571/1[]', "Hello", true)
await db.push('/issue571/1[]', "world", true)
let data = await db.getObject("/issue571/1[0]");
expect(data).toBe("Hello");
data = await db.getObject("/issue571/1[-1]");
expect(data).toBe("world");

}
)

test(
'should throw an error when trying to append to a non array',
async () => {
Expand Down

0 comments on commit db7b5cb

Please sign in to comment.