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

Unexpected matches behavior #61

Open
jumarko opened this issue Apr 5, 2019 · 1 comment
Open

Unexpected matches behavior #61

jumarko opened this issue Apr 5, 2019 · 1 comment

Comments

@jumarko
Copy link

jumarko commented Apr 5, 2019

I came across a surprising matches validator behavior: it marks a value as valid when only part of the value satisfies given regex:

(b/valid? {:name "ab"} {:name [v/required v/string [v/matches #"\w{1,2}"]]})
;;=> true

(b/valid? {:name "abc"} {:name [v/required v/string [v/matches #"\w{1,2}"]]})
;; should be false
;;=> true 

(re-matches #"\w{1,2}" "abc")
;;=> nil

;; even worse if we expect only digits
(b/valid? {:name "abc123def"} {:name [v/required v/string [v/matches #"\d+"]]})
;;=> true

Is this an expected behavior?

@jumarko
Copy link
Author

jumarko commented Apr 5, 2019

Is the expected usage pattern that we should use^ and $?

(b/valid? {:name "abc123def"} {:name [v/required v/string [v/matches #"^\d+$"]]})
;;=> false

(b/valid? {:name "123"} {:name [v/required v/string [v/matches #"^\d+$"]]})
;;=> true

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

1 participant