From 1037e8415b258545e147a5d7af49ed18ae33bace Mon Sep 17 00:00:00 2001 From: Thomas Bouldin Date: Wed, 31 May 2023 15:47:49 -0700 Subject: [PATCH 1/3] rtdb.exists returns true for falsy values --- package.json | 10 +++++----- spec/v1/providers/database.spec.ts | 9 +++++++++ src/common/providers/database.ts | 2 +- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 545568045..3c554b06d 100644 --- a/package.json +++ b/package.json @@ -93,16 +93,16 @@ "v1/pubsub": [ "./lib/v1/providers/pubsub" ], - "/v1/remoteConfig": [ + "v1/remoteConfig": [ "./lib/v1/providers/remoteConfig" ], - "/v1/storage": [ + "v1/storage": [ "./lib/v1/providers/storage" ], - "/v1/tasks": [ + "v1/tasks": [ "./lib/v1/providers/tasks" ], - "/v1/testLab": [ + "v1/testLab": [ "./lib/v1/providers/testLab" ], "v2": [ @@ -243,4 +243,4 @@ "engines": { "node": ">=14.10.0" } -} +} \ No newline at end of file diff --git a/spec/v1/providers/database.spec.ts b/spec/v1/providers/database.spec.ts index 9651961dc..d25ec4983 100644 --- a/spec/v1/providers/database.spec.ts +++ b/spec/v1/providers/database.spec.ts @@ -580,6 +580,15 @@ describe("DataSnapshot", () => { populate({ a: [{}] }); expect(subject.child("a").exists()).to.be.false; }); + + it("should be true for a falsy value (other than null)", () => { + populate({ num: 0, bool: false, n: null }); + expect(subject.exists()).to.be.true; + expect(subject.child("num").exists()).to.be.true; + expect(subject.child("bool").exists()).to.be.true; + expect(subject.child("n").exists()).to.be.false; + expect(subject.child("missing").exists()).to.be.false; + }) }); describe("#forEach(action: (a: DataSnapshot) => boolean): boolean", () => { diff --git a/src/common/providers/database.ts b/src/common/providers/database.ts index e1da47c7d..96642ea52 100644 --- a/src/common/providers/database.ts +++ b/src/common/providers/database.ts @@ -162,7 +162,7 @@ export class DataSnapshot implements database.DataSnapshot { */ exists(): boolean { const val = this.val(); - if (!val || val === null) { + if (typeof val === "undefined" || val === null) { return false; } if (typeof val === "object" && Object.keys(val).length === 0) { From 69035f54cee08820b9b8e79d335d31dcb0dc5e99 Mon Sep 17 00:00:00 2001 From: Daniel Lee Date: Mon, 12 Jun 2023 12:07:42 -0700 Subject: [PATCH 2/3] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d8b3095f7..faf1bacec 100644 --- a/package.json +++ b/package.json @@ -250,4 +250,4 @@ "engines": { "node": ">=14.10.0" } -} \ No newline at end of file +} From 398942333413c68d34957559ecfa4fa9253a8834 Mon Sep 17 00:00:00 2001 From: Daniel Lee Date: Mon, 12 Jun 2023 12:26:11 -0700 Subject: [PATCH 3/3] Update database.spec.ts --- spec/v1/providers/database.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/v1/providers/database.spec.ts b/spec/v1/providers/database.spec.ts index d25ec4983..874b1de29 100644 --- a/spec/v1/providers/database.spec.ts +++ b/spec/v1/providers/database.spec.ts @@ -588,7 +588,7 @@ describe("DataSnapshot", () => { expect(subject.child("bool").exists()).to.be.true; expect(subject.child("n").exists()).to.be.false; expect(subject.child("missing").exists()).to.be.false; - }) + }); }); describe("#forEach(action: (a: DataSnapshot) => boolean): boolean", () => {