-
Notifications
You must be signed in to change notification settings - Fork 215
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
re schema doesn't properly validate values with line breaks #862
Comments
This ultimately boils down to the difference in (let [pattern (Pattern/compile "^thing$")
matcher (.matcher pattern "thing\n")]
(.matches matcher))
=> false
(let [pattern (Pattern/compile "^thing$")
matcher (.matcher pattern "thing\n")]
(.find matcher))
=> true The javadoc on java.util.regex.Matcher/find states:
whereas the javadoc for java.util.regex.Matcher/matches states:
To me, at least, the functionality of java.util.regex.Matcher/matches, i.e clojure.core/re-matches, is what I'm expecting. |
Interesting. Tested with few alternatives: Plumatic(require '[schema.core :as schema])
(schema/validate #"thing" "thing\n")
; => "thing\n" (match) JSON Schema Spec{"type": "string", "pattern": "^thing$"}
// => null (match) JavascriptRegExp('^thing$').exec('thing\n')
// => null (no match) So, Malli works currently like Plumatic and JSON Schema do, but not like default JavaScript. |
Do you have more external references (on languages / libraries etc) on what is the correct way to handle this? Options:
|
I think the behavior for For example if I have the schema
I would expect that to match any string that contained |
I should also mention that you can always use (re-find "^string\z" "string\n") => nil See https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/regex/Pattern.html |
I didn't even know about |
Compare to
The text was updated successfully, but these errors were encountered: