paralleldrive/cuid2

Cuid validation failing

stctheproducer opened this issue · 4 comments

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.

The same problem here

const isCuid = (id, { minLength = 2, maxLength = bigLength } = {}) => {

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.

I am using v2.2.0

cuid.isCuid('undefined') // true

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".