Skip to content

Commit

Permalink
fix: switch IN operator to substring check (#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
khvn26 authored Jul 10, 2023
1 parent 2b5bdf2 commit 75d0c18
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
5 changes: 1 addition & 4 deletions flag_engine/segments/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,7 @@ def evaluate_modulo(self, trait_value: typing.Union[str, int, float, bool]) -> b
return trait_value % divisor == remainder

def evaluate_in(self, trait_value) -> bool:
try:
return str(trait_value) in self.value.split(",")
except AttributeError:
return False
return str(trait_value) in (self.value or "")


class SegmentRuleModel(BaseModel):
Expand Down
1 change: 1 addition & 0 deletions tests/unit/segments/test_segments_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
(constants.REGEX, None, r"[a-z]", False),
(constants.IN, "foo", "", False),
(constants.IN, "foo", "foo, bar", True),
(constants.IN, "bar", "foo, bar", True),
(constants.IN, "foo", "foo", True),
(constants.IN, 1, "1,2,3,4", True),
(constants.IN, 1, "", False),
Expand Down

0 comments on commit 75d0c18

Please sign in to comment.