Skip to content

Fix various v0.11.0 conformance issues #294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion protovalidate/internal/extra_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
15 changes: 2 additions & 13 deletions protovalidate/internal/string_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)

Expand Down
15 changes: 0 additions & 15 deletions tests/conformance/nonconforming.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading