From b87a6bc15ce2718b3a711cef226bba73d0a87cad Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Thu, 20 Jun 2024 13:22:16 +1000 Subject: [PATCH] Fix #4874. Checking restrictions of the wrong data type will now returned a failed result instead of an exception. --- src/ifctester/ifctester/facet.py | 63 +++++++++++++++++--------------- 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/src/ifctester/ifctester/facet.py b/src/ifctester/ifctester/facet.py index 580af2e4e8..a05a23f3a7 100644 --- a/src/ifctester/ifctester/facet.py +++ b/src/ifctester/ifctester/facet.py @@ -1025,37 +1025,40 @@ class Restriction: if other is None: return False for constraint, value in self.options.items(): - if constraint == "enumeration": - if other not in [cast_to_value(v, other) for v in value]: - return False - elif constraint == "pattern": - if not isinstance(other, str): - return False - value = value if isinstance(value, list) else [value] - for pattern in value: - if re.compile(identities.translate_pattern(pattern)).fullmatch(other) is None: + try: + if constraint == "enumeration": + if other not in [cast_to_value(v, other) for v in value]: return False - elif constraint == "length": - if len(str(other)) != int(value): - return False - elif constraint == "maxLength": - if len(str(other)) > int(value): - return False - elif constraint == "minLength": - if len(str(other)) < int(value): - return False - elif constraint == "maxExclusive": - if float(other) >= float(value): - return False - elif constraint == "maxInclusive": - if float(other) > float(value): - return False - elif constraint == "minExclusive": - if float(other) <= float(value): - return False - elif constraint == "minInclusive": - if float(other) < float(value): - return False + elif constraint == "pattern": + if not isinstance(other, str): + return False + value = value if isinstance(value, list) else [value] + for pattern in value: + if re.compile(identities.translate_pattern(pattern)).fullmatch(other) is None: + return False + elif constraint == "length": + if len(str(other)) != int(value): + return False + elif constraint == "maxLength": + if len(str(other)) > int(value): + return False + elif constraint == "minLength": + if len(str(other)) < int(value): + return False + elif constraint == "maxExclusive": + if float(other) >= float(value): + return False + elif constraint == "maxInclusive": + if float(other) > float(value): + return False + elif constraint == "minExclusive": + if float(other) <= float(value): + return False + elif constraint == "minInclusive": + if float(other) < float(value): + return False + except ValueError: + return False return True def __str__(self):