Skip to content

Commit 67d4adb

Browse files
committed
Fix infinite recursion on ref
Previously, when a document have a reference to another document, we ended up in an infinite loop. This is now prevented by only follow plain objects. This logic makes it easier to reason about the call chain too.
1 parent b8a2ebb commit 67d4adb

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/utils.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,9 @@ exports.removeEmptyRtdbProperties = function removeEmptyRtdbProperties(obj) {
128128
};
129129

130130
exports.removeEmptyFirestoreProperties = function removeEmptyFirestoreProperties(obj) {
131-
var t = typeof obj;
132-
if (t === 'boolean' || t === 'string' || t === 'number' || t === 'undefined') {
131+
if (!_.isPlainObject(obj)) {
133132
return obj;
134133
}
135-
if (obj instanceof Date) return obj;
136-
if (obj instanceof Timestamp) return obj;
137134

138135
var keys = getKeys(obj);
139136
if (keys.length > 0) {

test/unit/firestore-document.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,21 @@ describe('MockFirestoreDocument', function () {
199199

200200
db.flush();
201201
});
202+
203+
it.only('sets value of doc with ref', function (done) {
204+
var ref = db.doc('ref');
205+
ref.create();
206+
doc.set({
207+
ref: ref
208+
});
209+
doc.get().then(function(snap) {
210+
expect(snap.exists).to.equal(true);
211+
expect(snap.get('ref')).to.have.property('ref');
212+
done();
213+
}).catch(done);
214+
215+
db.flush();
216+
});
202217
});
203218

204219
describe('#set with {merge: true}', function () {

0 commit comments

Comments
 (0)