Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): fix bug about isObject function #3647

Merged
merged 2 commits into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/poor-suns-film.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@verdaccio/core': patch
---

fix(core): fix `isObject` function.`isObject(true)` should return false.
17 changes: 9 additions & 8 deletions packages/core/core/src/validation-utils.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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