From 91cf799b26a4bca87f61182685463c0ec70b5630 Mon Sep 17 00:00:00 2001 From: Sven Schmit Date: Tue, 14 May 2024 08:43:20 -0700 Subject: [PATCH 1/3] switch to using search instead of match in regex --- eppo_client/rules.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eppo_client/rules.py b/eppo_client/rules.py index bc7c969..0327651 100644 --- a/eppo_client/rules.py +++ b/eppo_client/rules.py @@ -49,11 +49,11 @@ def evaluate_condition( if subject_value is not None: if condition.operator == OperatorType.MATCHES: return isinstance(condition.value, str) and bool( - re.match(condition.value, str(subject_value)) + re.search(condition.value, str(subject_value)) ) if condition.operator == OperatorType.NOT_MATCHES: return isinstance(condition.value, str) and not bool( - re.match(condition.value, str(subject_value)) + re.search(condition.value, str(subject_value)) ) elif condition.operator == OperatorType.ONE_OF: return isinstance(condition.value, list) and str(subject_value).lower() in [ From d5c936efaf873c9caa2bebfe6cdf42b509044ff0 Mon Sep 17 00:00:00 2001 From: Sven Schmit Date: Tue, 14 May 2024 09:21:54 -0700 Subject: [PATCH 2/3] add test for partial matches --- test/rules_test.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/rules_test.py b/test/rules_test.py index 7741b48..049dbfc 100644 --- a/test/rules_test.py +++ b/test/rules_test.py @@ -143,6 +143,27 @@ def test_evaluate_condition_matches(): ) +def test_evaluate_condition_matches_partial(): + assert evaluate_condition( + Condition( + operator=OperatorType.MATCHES, value="@example\\.com", attribute="email" + ), + {"email": "alice@example.com"}, + ) + assert not evaluate_condition( + Condition( + operator=OperatorType.MATCHES, value="@example\\.com", attribute="email" + ), + {"email": "alice@sample.com"}, + ) + assert evaluate_condition( + Condition( + operator=OperatorType.MATCHES, value="@example\\.com", attribute="email" + ), + {"email": "bob@example.com"}, + ) + + def test_evaluate_condition_not_matches(): assert not evaluate_condition( Condition( From 0384c2e18d7d05675b82d1e0119e2133b60ca406 Mon Sep 17 00:00:00 2001 From: Sven Schmit Date: Tue, 14 May 2024 09:34:57 -0700 Subject: [PATCH 3/3] bump version --- eppo_client/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eppo_client/version.py b/eppo_client/version.py index 131942e..8d1c862 100644 --- a/eppo_client/version.py +++ b/eppo_client/version.py @@ -1 +1 @@ -__version__ = "3.0.2" +__version__ = "3.0.3"