Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue calling DataSnapshot methods with null data #1661

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

rhodgkins
Copy link
Contributor

@rhodgkins rhodgkins commented Jan 13, 2025

Description

Fixes firebase/firebase-functions-test#254

Fix is similar to the check in #exists():

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

@inlined
Copy link
Member

inlined commented Jan 22, 2025

@taeold IIUC this is a straight bugfix, but I wanted to double check that you don't consider this a breaking change.

@inlined inlined requested a review from taeold January 22, 2025 01:05
@taeold
Copy link
Contributor

taeold commented Jan 24, 2025

Feels like this is a good change and not breaking.

IIUC the change would only break if the traversing the full path instead of short-circuiting somehow had a side effect that was worthy.

@rhodgkins
Copy link
Contributor Author

@taeold any ideas on the timeline when this might be merged / released?

@rhodgkins rhodgkins force-pushed the master branch 2 times, most recently from 4a917c5 to 29ff57d Compare February 5, 2025 12:41
@rhodgkins
Copy link
Contributor Author

Sorry I missed that there were tests in the project for this! I've added some tests for the issue to make it clearer.
I've also update the fix as adding tests exposed another issue when this._data is directly null (and not as a result of a child being missing or null).

@@ -128,7 +128,7 @@ export class DataSnapshot implements database.DataSnapshot {
let source = this._data;
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") {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants