Skip to content

Commit 8b48e57

Browse files
committed
Add tests, fix bug
1 parent 118e8a6 commit 8b48e57

File tree

2 files changed

+612
-127
lines changed

2 files changed

+612
-127
lines changed

splitio/matchers.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from sys import modules
66

77
from future.utils import python_2_unicode_compatible
8-
8+
from six import string_types
99
from splitio.transformers import AsDateHourMinuteTimestampTransformMixin, \
1010
AsNumberTransformMixin, AsDateTimestampTransformMixin, TransformMixin
1111

@@ -485,7 +485,8 @@ def match(self, key):
485485
:return: True under the conditiones described above
486486
:rtype: bool
487487
"""
488-
return any(key.startswith(s) for s in self._whitelist)
488+
return (isinstance(key, string_types) and
489+
any(key.startswith(s) for s in self._whitelist))
489490

490491
@python_2_unicode_compatible
491492
def __str__(self):
@@ -512,7 +513,8 @@ def match(self, key):
512513
:return: True under the conditiones described above
513514
:rtype: bool
514515
"""
515-
return any(key.endswith(s) for s in self._whitelist)
516+
return (isinstance(key, string_types) and
517+
any(key.endswith(s) for s in self._whitelist))
516518

517519
@python_2_unicode_compatible
518520
def __str__(self):
@@ -539,7 +541,8 @@ def match(self, key):
539541
:return: True under the conditiones described above
540542
:rtype: bool
541543
"""
542-
return any(s in key for s in self._whitelist)
544+
return (isinstance(key, string_types) and
545+
any(s in key for s in self._whitelist))
543546

544547
@python_2_unicode_compatible
545548
def __str__(self):
@@ -664,7 +667,7 @@ def match(self, key):
664667
"""
665668
try:
666669
setkey = set(key)
667-
return setkey.issubset(set(self._whitelist))
670+
return len(setkey) > 0 and setkey.issubset(set(self._whitelist))
668671
except TypeError:
669672
return False
670673

0 commit comments

Comments
 (0)