Skip to content

Commit

Permalink
fix(core): fix bug about isObject function, it should return false wh…
Browse files Browse the repository at this point in the history
…en input is a boolean

This bug will case
[request](https://github.com/verdaccio/verdaccio/blob/bae430fe24c9bb63dcf7b7b9e5f9f0dbf3f42669/src/lib/up-storage.ts#L157)
has a body when options.json is `true`.

fix verdaccio#3601
  • Loading branch information
botao-tal committed Feb 23, 2023
1 parent 30a967a commit 8bce011
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
17 changes: 9 additions & 8 deletions packages/core/core/src/validation-utils.ts
Expand Up @@ -95,14 +95,15 @@ export function normalizeMetadata(manifest: Manifest, name: string): Manifest {
* @return {Boolean}
*/
export function isObject(obj: any): boolean {
if (obj === null || typeof obj === 'undefined' || typeof obj === 'string') {
return false;
}

return (
(typeof obj === 'object' || typeof obj.prototype === 'undefined') &&
Array.isArray(obj) === false
);
// if (obj === null || typeof obj === 'undefined' || typeof obj === 'string') {
// return false;
// }

// return (
// (typeof obj === 'object' || typeof obj.prototype === 'undefined') &&
// Array.isArray(obj) === false
// );
return Object.prototype.toString.call(obj) === '[object Object]';
}

export function validatePassword(
Expand Down
1 change: 1 addition & 0 deletions packages/core/core/test/validation-utilts.spec.ts
Expand Up @@ -31,6 +31,7 @@ describe('isObject', () => {
expect(isObject(['foo'])).toBeFalsy();
expect(isObject(null)).toBeFalsy();
expect(isObject(undefined)).toBeFalsy();
expect(isObject(true)).toBeFalsy();
});
});

Expand Down

0 comments on commit 8bce011

Please sign in to comment.