Skip to content
Open
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
11 changes: 11 additions & 0 deletions spec/v1/providers/database.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,20 +494,31 @@ describe("DataSnapshot", () => {
it("should deal with null-values appropriately", () => {
populate(null);
expect(subject.val()).to.be.null;
expect(subject.child("a").val()).to.be.null;
expect(subject.child("a/b").val()).to.be.null;

populate({ myKey: null });
expect(subject.val()).to.be.null;
expect(subject.child("myKey").val()).to.be.null;
expect(subject.child("myKey/a").val()).to.be.null;
expect(subject.child("myKey/a/b").val()).to.be.null;
expect(subject.child("a").val()).to.be.null;
expect(subject.child("a/b").val()).to.be.null;
});

it("should deal with empty object values appropriately", () => {
populate({});
expect(subject.val()).to.be.null;
expect(subject.child("a").val()).to.be.null;

populate({ myKey: {} });
expect(subject.val()).to.be.null;
expect(subject.child("myKey").val()).to.be.null;

populate({ myKey: { child: null } });
expect(subject.val()).to.be.null;
expect(subject.child("myKey").val()).to.be.null;
expect(subject.child("myKey/child").val()).to.be.null;
});

it("should deal with empty array values appropriately", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/common/providers/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export class DataSnapshot implements database.DataSnapshot {
}
if (parts.length) {
for (const part of parts) {
if (source[part] === undefined) {
if (typeof source === "undefined" || source === null) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As well as moving this "up" to the parent object I've also changed the check from === undefined to a typeof so it matches the other checks elsewhere:

if (typeof val === "undefined" || val === null) {

if (node === null || typeof node === "undefined") {

return null;
}
source = source[part];
Expand Down