From 3c04f4caf72cc35ab4631cba403b44e5f9b11bdf Mon Sep 17 00:00:00 2001
From: wallace-sf <wallaceedua@gmail.com>
Date: Thu, 27 Jun 2024 22:56:35 -0300
Subject: [PATCH] fix: array unique duplicated null or undefined

---
 src/decorator/array/ArrayUnique.ts                          | 4 +++-
 test/functional/validation-functions-and-decorators.spec.ts | 2 +-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/decorator/array/ArrayUnique.ts b/src/decorator/array/ArrayUnique.ts
index 0979aeefc0..95e5085d01 100644
--- a/src/decorator/array/ArrayUnique.ts
+++ b/src/decorator/array/ArrayUnique.ts
@@ -12,7 +12,9 @@ export function arrayUnique(array: unknown[], identifier?: ArrayUniqueIdentifier
   if (!Array.isArray(array)) return false;
 
   if (identifier) {
-    array = array.map(o => (o != null ? identifier(o) : o));
+    array = array.map(o => (o != null ? identifier(o) : o)).filter(o => o != null);
+
+    if (array.length === 0) return true;
   }
 
   const uniqueItems = array.filter((a, b, c) => c.indexOf(a) === b);
diff --git a/test/functional/validation-functions-and-decorators.spec.ts b/test/functional/validation-functions-and-decorators.spec.ts
index 78ceddcd6d..12246aaf40 100644
--- a/test/functional/validation-functions-and-decorators.spec.ts
+++ b/test/functional/validation-functions-and-decorators.spec.ts
@@ -4572,7 +4572,7 @@ describe('ArrayUnique with identifier', () => {
     ['world', 'hello', 'superman'],
     ['world', 'superman', 'hello'],
     ['superman', 'world', 'hello'],
-    ['1', '2', null, undefined],
+    ['1', '2', null, null, undefined, undefined],
   ].map(list => list.map(name => ({ name })));
   const invalidValues: any[] = [
     null,