typestack / class-validator

Decorator-based property validation for classes.
MIT License
10.92k stars 787 forks source link

fix: Array Unique wrong validation for nullable values #2498

Open wallace-sf opened 3 months ago

wallace-sf commented 3 months ago

Description

Hey guys. I was trying to validate some data and I found a different behavior from the decorator ArrayUnique. According to the docs, If null or undefined is given then this function returns false., but this is not what is happening. The function returns true.

Minimal code-snippet showcasing the problem

Click here for Sandbox

The code is in the example.ts file in the src directory.

Expected behavior

The validation should not return any errors.

Actual behavior

The ArrayUnique decorator is not validating null or undefined duplicated values. These values should be ignored and the function should return false, but it is returning true.