Skip to content
This repository was archived by the owner on Nov 8, 2024. It is now read-only.

Commit b7ec99b

Browse files
authored
[UFC] Use partial instead of full match for regex (#37)
1 parent 9985719 commit b7ec99b

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

eppo_client/rules.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ def evaluate_condition(
4949
if subject_value is not None:
5050
if condition.operator == OperatorType.MATCHES:
5151
return isinstance(condition.value, str) and bool(
52-
re.match(condition.value, str(subject_value))
52+
re.search(condition.value, str(subject_value))
5353
)
5454
if condition.operator == OperatorType.NOT_MATCHES:
5555
return isinstance(condition.value, str) and not bool(
56-
re.match(condition.value, str(subject_value))
56+
re.search(condition.value, str(subject_value))
5757
)
5858
elif condition.operator == OperatorType.ONE_OF:
5959
return isinstance(condition.value, list) and str(subject_value).lower() in [

eppo_client/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "3.0.2"
1+
__version__ = "3.0.3"

test/rules_test.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,27 @@ def test_evaluate_condition_matches():
143143
)
144144

145145

146+
def test_evaluate_condition_matches_partial():
147+
assert evaluate_condition(
148+
Condition(
149+
operator=OperatorType.MATCHES, value="@example\\.com", attribute="email"
150+
),
151+
{"email": "[email protected]"},
152+
)
153+
assert not evaluate_condition(
154+
Condition(
155+
operator=OperatorType.MATCHES, value="@example\\.com", attribute="email"
156+
),
157+
{"email": "[email protected]"},
158+
)
159+
assert evaluate_condition(
160+
Condition(
161+
operator=OperatorType.MATCHES, value="@example\\.com", attribute="email"
162+
),
163+
{"email": "[email protected]"},
164+
)
165+
166+
146167
def test_evaluate_condition_not_matches():
147168
assert not evaluate_condition(
148169
Condition(

0 commit comments

Comments
 (0)