FirebaseExtended / angularfire

AngularJS bindings for Firebase
MIT License
2.73k stars 632 forks source link

utils method "toJson" won't recursively check values #928

Closed klifa90 closed 7 years ago

klifa90 commented 7 years ago

Specifically this part

angular.forEach(dat, function(v,k) {
              if (k.match(/[.$\[\]#\/]/) && k !== '.value' && k !== '.priority' ) {
                throw new Error('Invalid key ' + k + ' (cannot contain .$[]#)');
              }
              else if( angular.isUndefined(v) ) {
                throw new Error('Key '+k+' was undefined. Cannot pass undefined in JSON. Use null instead.');
              }
            });

If you have nested objects like:

{ name : "jhon",
  phone : "12345",
  address: 
{
  street : "1st st",
  number : undefined
}
}

It will never detect that "number" is undefined and will not throw error, firebase sync will fail then every time.

I know that if it is receiving undefined then it must be a code bug (which i don't share), but anyways, if you are already checking, why are you not checking recursively?

davideast commented 7 years ago

Hi @klifa90! We have a required issue template. I'm going to close this issue, but free to open a new one that follows the template. Also if you could provide a plnkr that demonstrates the problem that would help out tremendously!