fix(validation): accept an empty string as the unset value of an int

This commit is contained in:
2026-10-05 19:25:02 +02:00
parent e52696a509
commit 0ce2590568
2 changed files with 9 additions and 2 deletions
+3 -2
View File
@@ -20,10 +20,11 @@ SPEC_KEYS = {"type", "required", "default", "choices", "elements", "options", "d
UNRESOLVED = object() UNRESOLVED = object()
# Numbers pass where a string is declared and digit strings where an int is: the roles read those # Numbers pass where a string is declared and digit strings where an int is: the roles read those
# through `| string` and `| int` unchanged. A string posing as a list, bool or dict never passes. # through `| string` and `| int` unchanged. An empty string is the contract's unset int, as in
# `system.vlan: ""`. A string posing as a list, bool or dict never passes.
TYPES = { TYPES = {
"str": lambda v: isinstance(v, (str, int, float, EncryptedString)) and not isinstance(v, bool), "str": lambda v: isinstance(v, (str, int, float, EncryptedString)) and not isinstance(v, bool),
"int": lambda v: (isinstance(v, int) and not isinstance(v, bool)) or (isinstance(v, str) and v.isdigit()), "int": lambda v: (isinstance(v, int) and not isinstance(v, bool)) or (isinstance(v, str) and (v == "" or v.isdigit())),
"float": lambda v: isinstance(v, (int, float)) and not isinstance(v, bool), "float": lambda v: isinstance(v, (int, float)) and not isinstance(v, bool),
"bool": lambda v: isinstance(v, bool), "bool": lambda v: isinstance(v, bool),
"list": lambda v: isinstance(v, list), "list": lambda v: isinstance(v, list),
+6
View File
@@ -16,6 +16,12 @@ inputs_fixtures:
retired: ~ retired: ~
expect: [] expect: []
- name: empty-int-is-unset
value:
name: web01
count: ""
expect: []
- name: list-for-dict - name: list-for-dict
value: value:
name: web01 name: web01