From 378e907d537d27b35a3f9a21049c90724d28e6ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=96=84=E6=B6=9B?= Date: Thu, 23 Feb 2023 18:24:26 +0800 Subject: [PATCH] fix(core): fix bug about isObject function (#3647) --- .changeset/poor-suns-film.md | 5 +++++ packages/core/core/src/validation-utils.ts | 15 ++++++++------- packages/core/core/test/validation-utilts.spec.ts | 1 + 3 files changed, 14 insertions(+), 7 deletions(-) create mode 100644 .changeset/poor-suns-film.md diff --git a/.changeset/poor-suns-film.md b/.changeset/poor-suns-film.md new file mode 100644 index 000000000..816884177 --- /dev/null +++ b/.changeset/poor-suns-film.md @@ -0,0 +1,5 @@ +--- +'@verdaccio/core': patch +--- + +fix(core): fix `isObject` function.`isObject(true)` should return false. diff --git a/packages/core/core/src/validation-utils.ts b/packages/core/core/src/validation-utils.ts index 127406859..403410d69 100644 --- a/packages/core/core/src/validation-utils.ts +++ b/packages/core/core/src/validation-utils.ts @@ -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; - } + // if (obj === null || typeof obj === 'undefined' || typeof obj === 'string') { + // return false; + // } - return ( - (typeof obj === 'object' || typeof obj.prototype === 'undefined') && - Array.isArray(obj) === false - ); + // return ( + // (typeof obj === 'object' || typeof obj.prototype === 'undefined') && + // Array.isArray(obj) === false + // ); + return Object.prototype.toString.call(obj) === '[object Object]'; } export function validatePassword( diff --git a/packages/core/core/test/validation-utilts.spec.ts b/packages/core/core/test/validation-utilts.spec.ts index 0ea0faec1..9d2d7cdcf 100644 --- a/packages/core/core/test/validation-utilts.spec.ts +++ b/packages/core/core/test/validation-utilts.spec.ts @@ -31,6 +31,7 @@ describe('isObject', () => { expect(isObject(['foo'])).toBeFalsy(); expect(isObject(null)).toBeFalsy(); expect(isObject(undefined)).toBeFalsy(); + expect(isObject(true)).toBeFalsy(); }); });