Skip to content

Commit 87472f3

Browse files
authored
Fix bug where onCall handler failed to encode returned value that contained a function (#1000)
In #915, we replaced use of `_.isObject(data)` with `typeof data === 'object'`. Turns out that `_.isObject` returns `true` for functions ([code](https://github.com/lodash/lodash/blob/2da024c3b4f9947a48517639de7560457cd4ec6c/isObject.js#L26)). We update the condition to match the previous behavior. Fixes #964
1 parent 43e68af commit 87472f3

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
- GCS Enhancement
2-
- Add option to allow callable functions to ignore invalid App Check tokens.
2+
- Add option to allow callable functions to ignore invalid App Check tokens
33
- Add firebase-admin v10 as an allowed peer dependency
4+
- Fix bug where onCall handler failed to encode returned value with functions

spec/common/providers/https.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,4 +665,8 @@ describe('encoding/decoding', () => {
665665
baz: [1, 2, 1099511627776],
666666
});
667667
});
668+
669+
it('encodes function as an empty object', () => {
670+
expect(https.encode(() => 'foo')).to.deep.equal({});
671+
});
668672
});

src/common/providers/https.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ export function encode(data: any): any {
426426
if (Array.isArray(data)) {
427427
return data.map(encode);
428428
}
429-
if (typeof data === 'object') {
429+
if (typeof data === 'object' || typeof data === 'function') {
430430
// Sadly we don't have Object.fromEntries in Node 10, so we can't use a single
431431
// list comprehension
432432
const obj: Record<string, any> = {};

0 commit comments

Comments
 (0)