Skip to content

Commit

Permalink
fix(database, update): allow empty objects in ref.update()
Browse files Browse the repository at this point in the history
As pointed out by @daveGregorian firebase-js-sdk allows empty objects
while the code here was enforcing that the objects had at least one key

Fixes #5218
  • Loading branch information
mikehardy committed Apr 28, 2021
1 parent a51e97b commit 574f691
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
18 changes: 8 additions & 10 deletions packages/database/e2e/reference/update.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,6 @@ describe('database().ref().update()', function () {
}
});

it('throws if values does not contain any values', async function () {
try {
await firebase.database().ref(TEST_PATH).update({});
return Promise.reject(new Error('Did not throw an Error.'));
} catch (error) {
error.message.should.containEql("'values' must be an object containing multiple values");
return Promise.resolve();
}
});

it('throws if update paths are not valid', async function () {
try {
await firebase.database().ref(TEST_PATH).update({
Expand Down Expand Up @@ -83,6 +73,14 @@ describe('database().ref().update()', function () {
foo: value,
}),
);

await ref.update({}); // empty update should pass, but no side effects
const snapshot2 = await ref.once('value');
snapshot2.val().should.eql(
jet.contextify({
foo: value,
}),
);
});

it('callback if function is passed', async function () {
Expand Down
6 changes: 0 additions & 6 deletions packages/database/lib/DatabaseReference.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,6 @@ export default class DatabaseReference extends DatabaseQuery {
throw new Error("firebase.database().ref().update(*) 'values' must be an object.");
}

if (!Object.keys(values).length) {
throw new Error(
"firebase.database().ref().update(*) 'values' must be an object containing multiple values.",
);
}

const keys = Object.keys(values);
for (let i = 0; i < keys.length; i++) {
if (!isValidPath(keys[i])) {
Expand Down

1 comment on commit 574f691

@vercel
Copy link

@vercel vercel bot commented on 574f691 Apr 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.