Skip to content

Commit 64adeeb

Browse files
author
John Chadwick
committed
Fix various v0.11.0 conformance issues
We still have the nanosecond granularity issues that we've always had, but this should fix everything else.
1 parent c3e7516 commit 64adeeb

File tree

3 files changed

+7
-29
lines changed

3 files changed

+7
-29
lines changed

protovalidate/internal/extra_func.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,8 @@ def get_bits(self) -> int:
548548

549549
# Handle double colon, fill pieces with 0
550550
if self._double_colon_seen:
551+
if len(p16) >= 7:
552+
return 0
551553
while len(p16) < 8:
552554
# Delete 0 entries at pos, insert a 0
553555
p16.insert(self._double_colon_at, 0x00000000)
@@ -677,7 +679,9 @@ def __address_part(self) -> bool:
677679

678680
break
679681

680-
return self._double_colon_seen or len(self._pieces) == 8
682+
if self._double_colon_seen:
683+
return len(self._pieces) < 8
684+
return len(self._pieces) == 8
681685

682686
def __zone_id(self) -> bool:
683687
"""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)