Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

length-of does not work for vectors #44

Open
spiffytech opened this issue Oct 14, 2015 · 2 comments
Open

length-of does not work for vectors #44

spiffytech opened this issue Oct 14, 2015 · 2 comments

Comments

@spiffytech
Copy link

cms.validation=> ((vr/length-of :stuff :is 5) {:stuff [1 2 3 4 5]})

ClassCastException clojure.lang.PersistentVector cannot be cast to java.lang.CharSequence  clojure.string/blank? (string.clj:291)

I see you're using count under the hood, so length-of should be adaptable? In any case, it would sure be great to have a vector length validation function in Validateur.

@michaelklishin
Copy link
Owner

@spiffytech feel free to submit a PR for that. We'd have two cases: strings (char sequences) and collections. Those can use different core functions.

@michalmarczyk
Copy link
Contributor

The problem here is that

  1. length-of includes a nil check and a blank string check using not-allowed-to-be-blank? under the hood;
  2. not-allowed-to-be-blank? blindly applies string/blank? to its input, whether it is a string or not;
  3. this cannot even be overridden with allow-blank true, because not-allowed-to-be-blank? checks allowed-blank last, so it always makes the string/blank? call, even if unnecessary;
  4. this same check is then repeated (with inverted Boolean logic, but same end effect) in equal-length-of and range-length-of, so it'd also need to be fixed there.

The main size/length/count check would indeed accept anything that count knows how to handle, including vectors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants