Check for invalid version with leading zeros

This commit is contained in:
Ivan Kravets
2022-02-21 18:02:56 +02:00
parent 4d9547066b
commit 6bed610af3
2 changed files with 11 additions and 0 deletions

View File

@ -236,6 +236,12 @@ class ManifestSchema(BaseSchema):
try:
value = str(value)
assert "." in value
# check leading zeros
try:
semantic_version.Version(value)
except ValueError as exc:
if "Invalid leading zero" in str(exc):
raise exc
semantic_version.Version.coerce(value)
except (AssertionError, ValueError):
raise ValidationError(

View File

@ -859,6 +859,11 @@ def test_broken_schemas():
ManifestValidationError, match=("Invalid semantic versioning format")
):
ManifestSchema().load_manifest(dict(name="MyPackage", version="broken_version"))
# version with leading zeros
with pytest.raises(
ManifestValidationError, match=("Invalid semantic versioning format")
):
ManifestSchema().load_manifest(dict(name="MyPackage", version="01.02.00"))
# broken value for Nested
with pytest.raises(ManifestValidationError, match=r"authors.*Invalid input type"):