Cuid validation failing
stctheproducer opened this issue · 4 comments
stctheproducer commented
There's a bug with the validation function. It's returning true regardless of the value.
Expected
import { createId, isCuid } from '@paralleldrive/cuid2';
console.log(
isCuid(createId()), // true
isCuid('not a cuid'), // false
)
Actual Results
import c from '@paralleldrive/cuid2'
let id = c.createId()
console.log(id) // ehx2jphxcar7ihzxquylc8vr
c.isCuid(id) // true
c.isCuid('user') // true
c.isCuid('') // false
c.isCuid(2) // false
I'm running node v18.17.0
.
patrickalima98 commented
The same problem here
stctheproducer commented
Line 103 in fb07094
I just realized the function call takes in a minLength
and the default is 24. I guess, I'll have to be explicit about that or just use a custom regex pattern in the code.
mittalyashu commented
I am using v2.2.0
cuid.isCuid('undefined') // true
ericelliott commented
unfortunately, the string (NOT the value), "undefined"
is indeed a valid cuid.
That's just the nature of a very large domain of random alphanumeric characters.
It is working as intended, but perhaps we could hand-code some common exceptions, like "undefined".