Commits
Click on a commit to change the comparison rangestring: Use 're.Pattern.search' instead of 're.Pattern.match'
Rust's 'Regex.is_match' behaves like Python's 're.Pattern.search',
here's a snippet from the docs of the former:
Returns true if and only if there is a match for the regex *anywhere*
in the haystack given.
Given the implementation of the regex matching mechanism for the
'validators.string.Pattern', this leads to an inconsistent behavior:
import re
from pydantic import BaseModel, Field
class A(BaseModel):
b: str = Field(pattern=r"[a-z]")
c: str = Field(pattern=re.compile(r"[a-z]"))
A.model_validate({"b": "Abc", "c": "Abc"})
In this snippet od code, 'b' will validate fine, but 'c' won't.
Since the test cases for string already establish the expected behavior
(the Rust's `Regex.is_match` case), let's use `re.Pattern.search`
instead of `re.Pattern.match` to unify the results when a `re.Pattern`
object is passed.
Signed-off-by: Marcin Sobczyk <msobczyk@redhat.com>