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

string: Use 're.Pattern.search' instead of 're.Pattern.match' #1368

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/validators/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ impl Pattern {
match &self.engine {
RegexEngine::RustRegex(regex) => Ok(regex.is_match(target)),
RegexEngine::PythonRe(py_regex) => {
Ok(!py_regex.call_method1(py, intern!(py, "match"), (target,))?.is_none(py))
Ok(!py_regex.call_method1(py, intern!(py, "search"), (target,))?.is_none(py))
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions tests/validators/test_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ def test_str_not_json(input_value, expected):
({'pattern': r'^\d+$'}, '12345', '12345'),
({'pattern': r'\d+$'}, 'foobar 123', 'foobar 123'),
({'pattern': r'^\d+$'}, '12345a', Err("String should match pattern '^\\d+$' [type=string_pattern_mismatch")),
({'pattern': r'[a-z]'}, 'Abc', 'Abc'),
({'pattern': re.compile(r'[a-z]')}, 'Abc', 'Abc'),
# strip comes after length check
({'max_length': 5, 'strip_whitespace': True}, '1234 ', '1234'),
# to_upper and strip comes after pattern check
Expand Down