Skip to content

Commit

Permalink
Fixes access on deeply nested, nonexistent property (#1432)
Browse files Browse the repository at this point in the history
* return null on nonexistent deeply nested property

* update changelog

* check specifically for undefined in val()

* fix lint issue

---------

Co-authored-by: Cole Rogers <colerogers@users.noreply.github.com>
  • Loading branch information
blidd-google and colerogers authored Jan 26, 2024
1 parent b661935 commit e6f5d89
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fixes access on deeply nested, nonexistent property. (#1432)
1 change: 1 addition & 0 deletions spec/v1/providers/database.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ describe("DataSnapshot", () => {
populate(applyChange({ a: 23 }, { b: 33 }));
expect(subject.child("a/b").val()).to.be.null;
expect(subject.child("b/c").val()).to.be.null;
expect(subject.child("a/b/c").val()).to.be.null;
});

it("should return a leaf value", () => {
Expand Down
3 changes: 3 additions & 0 deletions src/common/providers/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ export class DataSnapshot implements database.DataSnapshot {
let source = this._data;
if (parts.length) {
for (const part of parts) {
if (source[part] === undefined) {
return null;
}
source = source[part];
}
}
Expand Down

0 comments on commit e6f5d89

Please sign in to comment.