diff --git a/protovalidate/internal/extra_func.py b/protovalidate/internal/extra_func.py index c6cb19d5..ae2b02c0 100644 --- a/protovalidate/internal/extra_func.py +++ b/protovalidate/internal/extra_func.py @@ -677,7 +677,9 @@ def __address_part(self) -> bool: break - return self._double_colon_seen or len(self._pieces) == 8 + if self._double_colon_seen: + return len(self._pieces) < 8 + return len(self._pieces) == 8 def __zone_id(self) -> bool: """Determine whether the current position is a zoneID. diff --git a/protovalidate/internal/string_format.py b/protovalidate/internal/string_format.py index b6b1338d..9353ccf9 100644 --- a/protovalidate/internal/string_format.py +++ b/protovalidate/internal/string_format.py @@ -158,7 +158,7 @@ def format_string(self, arg: celtypes.Value) -> celpy.Result: # True -> true return celtypes.StringType(str(arg).lower()) if isinstance(arg, celtypes.DoubleType): - return celtypes.StringType(f"{arg:.0f}") + return celtypes.StringType(f"{arg:g}") if isinstance(arg, celtypes.DurationType): return celtypes.StringType(self._format_duration(arg)) if isinstance(arg, celtypes.TimestampType): @@ -168,23 +168,12 @@ def format_string(self, arg: celtypes.Value) -> celpy.Result: return celtypes.StringType(base.removesuffix("+00:00") + "Z") return celtypes.StringType(arg) - def format_value(self, arg: celtypes.Value) -> celpy.Result: - if isinstance(arg, (celtypes.StringType, str)): - return celtypes.StringType(quote(arg)) - if isinstance(arg, celtypes.UintType): - return celtypes.StringType(arg) - if isinstance(arg, celtypes.DurationType): - return celtypes.StringType(f'duration("{self._format_duration(arg)}")') - if isinstance(arg, celtypes.DoubleType): - return celtypes.StringType(f"{arg:f}") - return self.format_string(arg) - def format_list(self, arg: celtypes.ListType) -> celpy.Result: result = "[" for i in range(len(arg)): if i > 0: result += ", " - result += self.format_value(arg[i]) + result += self.format_string(arg[i]) result += "]" return celtypes.StringType(result) diff --git a/tests/conformance/nonconforming.yaml b/tests/conformance/nonconforming.yaml index 9a014fb4..b46684df 100644 --- a/tests/conformance/nonconforming.yaml +++ b/tests/conformance/nonconforming.yaml @@ -3,22 +3,7 @@ standard_rules/well_known_types/duration: - gte_lte/invalid/above - lte/invalid - - in/invalid - not in/valid - - not in/invalid standard_rules/well_known_types/timestamp: - gte_lte/invalid/above - lte/invalid -kitchen_sink: - - field/embedded/invalid - - field/transitive/invalid - - many/all-non-message-fields/invalid - - field/invalid -standard_rules/repeated: - - items/in/invalid - - items/not_in/invalid -library/is_ip: - - version/6/invalid/ipv6/7h16_double_colon_1h16 - - version/6/invalid/ipv6/7h16_double_colon - - version/6/invalid/ipv6/double_colon_8h16 - - version/6/invalid/ipv6/1h16_double_colon_7h16