Broken regex validation - Readme / Docs need update?
Closed this issue · 1 comments
I was using validator v0.16 without any issues.
I did not update to anything newer until now, because my compiler started yelling at me like crazy and I just did not have the time to deal with this.
I now decided to take a deeper look into what the issues are, and its mostly the regex validation that broke.
Just a short example, what I was doing with v0.16:
// the regex was defined somewhere else to be re-used in a lot of places, but that doesn't matter here
pub static RE_TEXT_1000: Lazy<Regex> =
Lazy::new(|| Regex::new(r"^[a-zA-Z0-9À-ÿ&.,_/()\s-]{0,1000}$").unwrap());
#[derive(Debug, Clone, Serialize, Deserialize, Validate)]
pub struct MyValidatedStruct {
#[validate(regex(path = "RE_TEXT_1000", code = "^[a-zA-Z0-9À-ÿ&.,_/()\\s-]{0,1000}$"))]
pub text: String,
}
This breaks when I am trying to use any version past v0.16.
The compiler complains about validator::validation::regex::AsRegex
not being implemented:
error[E0277]: the trait bound `once_cell::sync::Lazy<regex::Regex>: validator::validation::regex::AsRegex` is not satisfied
--> common/src/api_types/timetracking/record.rs:7:48
|
7 | #[derive(Debug, Clone, Serialize, Deserialize, Validate)]
| ^^^^^^^^ the trait `validator::validation::regex::AsRegex` is not implemented for `once_cell::sync::Lazy<regex::Regex>`, which is required by `&once_cell::sync::Lazy<regex::Regex>: validator::validation::regex::AsRegex`
|
= note: required for `&once_cell::sync::Lazy<regex::Regex>` to implement `validator::validation::regex::AsRegex`
note: required by a bound in `validate_regex`
--> /home/sd/.cargo/registry/src/index.crates.io-6f17d22bba15001f/validator-0.18.1/src/validation/regex.rs:57:42
|
57 | fn validate_regex(&self, regex: impl AsRegex) -> bool;
| ^^^^^^^ required by this bound in `ValidateRegex::validate_regex`
= note: this error originates in the derive macro `Validate` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider dereferencing here
|
17 | #[validate(regex(path = *"RE_TEXT_1000"))]
| +
The compiler hint with dereferencing is almost correct.
I can fix it with adding *
inside the quotes like so:
#[validate(regex(path = "*RE_TEXT_1000"))]
Is this to be expected? If so, an update of readme and docs would probably be nice.
Thanks I've updated the README.