Skip to content

Commit 9f2c63a

Browse files
rhodgkinstaeold
andauthored
Fixed issue calling DataSnapshot methods with null data (#1661)
* Fixed issue calling DataSnapshot methods with null data (see firebase/firebase-functions-test#254) * Added test cases for fix * Better fix for calling DataSnapshot#val() with null data * Add changelog. --------- Co-authored-by: Daniel Lee <danielylee@google.com> Co-authored-by: Daniel Lee <taeold@gmail.com>
1 parent f268680 commit 9f2c63a

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
- Add LLM guidance (#1736)
2+
- Fix issue calling DataSnapshot methods with null data (#1661)
23
- Adds auth.rawToken to context to allow access to the underlying token. (#1678)
34
- Fix logger runtime exceptions #(1704)

spec/v1/providers/database.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,20 +494,31 @@ describe("DataSnapshot", () => {
494494
it("should deal with null-values appropriately", () => {
495495
populate(null);
496496
expect(subject.val()).to.be.null;
497+
expect(subject.child("a").val()).to.be.null;
498+
expect(subject.child("a/b").val()).to.be.null;
497499

498500
populate({ myKey: null });
499501
expect(subject.val()).to.be.null;
502+
expect(subject.child("myKey").val()).to.be.null;
503+
expect(subject.child("myKey/a").val()).to.be.null;
504+
expect(subject.child("myKey/a/b").val()).to.be.null;
505+
expect(subject.child("a").val()).to.be.null;
506+
expect(subject.child("a/b").val()).to.be.null;
500507
});
501508

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

506514
populate({ myKey: {} });
507515
expect(subject.val()).to.be.null;
516+
expect(subject.child("myKey").val()).to.be.null;
508517

509518
populate({ myKey: { child: null } });
510519
expect(subject.val()).to.be.null;
520+
expect(subject.child("myKey").val()).to.be.null;
521+
expect(subject.child("myKey/child").val()).to.be.null;
511522
});
512523

513524
it("should deal with empty array values appropriately", () => {

src/common/providers/database.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ export class DataSnapshot implements database.DataSnapshot {
131131
}
132132
if (parts.length) {
133133
for (const part of parts) {
134-
if (source[part] === undefined) {
134+
if (typeof source === "undefined" || source === null) {
135135
return null;
136136
}
137137
source = source[part];

0 commit comments

Comments
 (0)