Skip to content

Commit a138869

Browse files
author
Martin Vrachev
committed
Validate spec_version during initialization
Even though version strings like "2.0.0-rc.2" or "1.0.0-beta" are valid strings in semantic versioning format, in TUF we never needed to add letters for our specification number. That's why I validate that: spec_version is a . separated string and when split it has a length of 3 and that each of the three elements is a number. Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
1 parent b39f198 commit a138869

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

tuf/api/metadata.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,11 @@ def __init__(
343343
expires: datetime,
344344
unrecognized_fields: Optional[Mapping[str, Any]] = None,
345345
) -> None:
346+
spec_list = spec_version.split(".")
347+
if len(spec_list) != 3 or not all(el.isdigit() for el in spec_list):
348+
raise ValueError(
349+
f"spec_version must be in semver format, got {spec_version}"
350+
)
346351
self.spec_version = spec_version
347352
self.expires = expires
348353

0 commit comments

Comments
 (0)