Skip to content

Commit 12155fb

Browse files
Fix various v0.11.0 conformance issues (#294)
We still have the nanosecond granularity issues that we've always had, but this should fix everything else. <!-- References TCN-2828. -->
1 parent d09b71f commit 12155fb

File tree

3 files changed

+5
-29
lines changed

3 files changed

+5
-29
lines changed

protovalidate/internal/extra_func.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,9 @@ def __address_part(self) -> bool:
677677

678678
break
679679

680-
return self._double_colon_seen or len(self._pieces) == 8
680+
if self._double_colon_seen:
681+
return len(self._pieces) < 8
682+
return len(self._pieces) == 8
681683

682684
def __zone_id(self) -> bool:
683685
"""Determine whether the current position is a zoneID.

protovalidate/internal/string_format.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def format_string(self, arg: celtypes.Value) -> celpy.Result:
158158
# True -> true
159159
return celtypes.StringType(str(arg).lower())
160160
if isinstance(arg, celtypes.DoubleType):
161-
return celtypes.StringType(f"{arg:.0f}")
161+
return celtypes.StringType(f"{arg:g}")
162162
if isinstance(arg, celtypes.DurationType):
163163
return celtypes.StringType(self._format_duration(arg))
164164
if isinstance(arg, celtypes.TimestampType):
@@ -168,23 +168,12 @@ def format_string(self, arg: celtypes.Value) -> celpy.Result:
168168
return celtypes.StringType(base.removesuffix("+00:00") + "Z")
169169
return celtypes.StringType(arg)
170170

171-
def format_value(self, arg: celtypes.Value) -> celpy.Result:
172-
if isinstance(arg, (celtypes.StringType, str)):
173-
return celtypes.StringType(quote(arg))
174-
if isinstance(arg, celtypes.UintType):
175-
return celtypes.StringType(arg)
176-
if isinstance(arg, celtypes.DurationType):
177-
return celtypes.StringType(f'duration("{self._format_duration(arg)}")')
178-
if isinstance(arg, celtypes.DoubleType):
179-
return celtypes.StringType(f"{arg:f}")
180-
return self.format_string(arg)
181-
182171
def format_list(self, arg: celtypes.ListType) -> celpy.Result:
183172
result = "["
184173
for i in range(len(arg)):
185174
if i > 0:
186175
result += ", "
187-
result += self.format_value(arg[i])
176+
result += self.format_string(arg[i])
188177
result += "]"
189178
return celtypes.StringType(result)
190179

tests/conformance/nonconforming.yaml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,7 @@
33
standard_rules/well_known_types/duration:
44
- gte_lte/invalid/above
55
- lte/invalid
6-
- in/invalid
76
- not in/valid
8-
- not in/invalid
97
standard_rules/well_known_types/timestamp:
108
- gte_lte/invalid/above
119
- lte/invalid
12-
kitchen_sink:
13-
- field/embedded/invalid
14-
- field/transitive/invalid
15-
- many/all-non-message-fields/invalid
16-
- field/invalid
17-
standard_rules/repeated:
18-
- items/in/invalid
19-
- items/not_in/invalid
20-
library/is_ip:
21-
- version/6/invalid/ipv6/7h16_double_colon_1h16
22-
- version/6/invalid/ipv6/7h16_double_colon
23-
- version/6/invalid/ipv6/double_colon_8h16
24-
- version/6/invalid/ipv6/1h16_double_colon_7h16

0 commit comments

Comments
 (0)