Skip to content

Commit 6e10d56

Browse files
authored
merge Switch to casefold from upper lower (#465)
merging #31
1 parent 2435c9d commit 6e10d56

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

statsig/evaluator.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -576,18 +576,18 @@ def __evaluate_condition(self, user, condition, end_result, context: EvaluationC
576576
value, condition)
577577
if op == "str_starts_with_any":
578578
return self.__match_string_in_array(
579-
value, target, lambda a, b: a.upper().lower().startswith(
580-
b.upper().lower()))
579+
value, target, lambda a, b: a.casefold().startswith(
580+
b.casefold()))
581581
if op == "str_ends_with_any":
582582
return self.__match_string_in_array(
583-
value, target, lambda a, b: a.upper().lower().endswith(
584-
b.upper().lower()))
583+
value, target, lambda a, b: a.casefold().endswith(
584+
b.casefold()))
585585
if op == "str_contains_any":
586586
return self.__match_string_in_array(
587-
value, target, lambda a, b: b.upper().lower() in a.upper().lower())
587+
value, target, lambda a, b: b.casefold() in a.casefold())
588588
if op == "str_contains_none":
589589
return not self.__match_string_in_array(
590-
value, target, lambda a, b: b.upper().lower() in a.upper().lower())
590+
value, target, lambda a, b: b.casefold() in a.casefold())
591591
if op == "str_matches":
592592
str_value = self.__get_value_as_string(value)
593593
str_target = self.__get_value_as_string(target)
@@ -649,14 +649,14 @@ def __get_from_user(self, user, field):
649649
if (value is None or value == "") and user.custom is not None:
650650
if field in user.custom:
651651
value = user.custom[field]
652-
elif field.upper().lower() in user.custom:
653-
value = user.custom[field.upper().lower()]
652+
elif field.casefold() in user.custom:
653+
value = user.custom[field.casefold()]
654654

655655
if (value is None or value == "") and self._global_custom_fields is not None:
656656
if field in self._global_custom_fields:
657657
value = self._global_custom_fields[field]
658-
elif field.upper().lower() in self._global_custom_fields:
659-
value = self._global_custom_fields[field.upper().lower()]
658+
elif field.casefold() in self._global_custom_fields:
659+
value = self._global_custom_fields[field.casefold()]
660660

661661
if (value is None or value == "") and user.private_attributes is not None:
662662
if field in user.private_attributes:
@@ -722,7 +722,7 @@ def __find_string_in_array(self, value, condition):
722722
if str_value is None or target is None:
723723
return False
724724
if op in ('any', 'none'):
725-
return str_value.upper().lower() in target
725+
return str_value.casefold() in target
726726
return str_value in target
727727

728728
def __arrays_have_common_value(self, value, condition):

statsig/spec_store.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ def _parse_target_value_for_condition(self, rule, condition_index, op, cond_type
416416
rule["conditions"][condition_index]["fast_target_value"] = {}
417417
for val in target_value:
418418
rule["conditions"][condition_index]["fast_target_value"][
419-
str(val).upper().lower()
419+
str(val).casefold()
420420
] = True
421421
elif op in (
422422
"any_case_sensitive",

0 commit comments

Comments
 (0)