Skip to content

Commit e6f5d89

Browse files
Fixes access on deeply nested, nonexistent property (#1432)
* return null on nonexistent deeply nested property * update changelog * check specifically for undefined in val() * fix lint issue --------- Co-authored-by: Cole Rogers <[email protected]>
1 parent b661935 commit e6f5d89

File tree

3 files changed

+5
-0
lines changed

3 files changed

+5
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Fixes access on deeply nested, nonexistent property. (#1432)

spec/v1/providers/database.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ describe("DataSnapshot", () => {
458458
populate(applyChange({ a: 23 }, { b: 33 }));
459459
expect(subject.child("a/b").val()).to.be.null;
460460
expect(subject.child("b/c").val()).to.be.null;
461+
expect(subject.child("a/b/c").val()).to.be.null;
461462
});
462463

463464
it("should return a leaf value", () => {

src/common/providers/database.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ export class DataSnapshot implements database.DataSnapshot {
120120
let source = this._data;
121121
if (parts.length) {
122122
for (const part of parts) {
123+
if (source[part] === undefined) {
124+
return null;
125+
}
123126
source = source[part];
124127
}
125128
}

0 commit comments

Comments
 (0)