Skip to content
Open
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
10 changes: 9 additions & 1 deletion src/univers/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ def build_value(cls, string):

@classmethod
def is_valid(cls, string):
if not super().is_valid(string):
return False
try:
cls.build_value(string)
return True
Expand Down Expand Up @@ -325,7 +327,7 @@ def build_value(cls, string):

@classmethod
def is_valid(cls, string):
return gem.GemVersion.is_correct(string)
return super().is_valid(string) and gem.GemVersion.is_correct(string)


class ArchLinuxVersion(Version):
Expand Down Expand Up @@ -375,6 +377,8 @@ def build_value(cls, string):

@classmethod
def is_valid(cls, string):
if not super().is_valid(string):
return False
try:
cls.build_value(string)
return True
Expand All @@ -392,6 +396,8 @@ def build_value(cls, string):

@classmethod
def is_valid(cls, string):
if not super().is_valid(string):
return False
try:
cls.build_value(string)
return True
Expand Down Expand Up @@ -664,6 +670,8 @@ def build_value(cls, string):

@classmethod
def is_valid(cls, string):
if not super().is_valid(string):
return False
try:
cls.build_value(string)
return True
Expand Down
23 changes: 23 additions & 0 deletions tests/test_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,3 +253,26 @@ def test_lexicographic_version():
assert LexicographicVersion("Abc") < LexicographicVersion(None)
assert LexicographicVersion("123") < LexicographicVersion("bbc")
assert LexicographicVersion("2.3.4") > LexicographicVersion("1.2.3")


def test_version_with_empty_string_is_invalid():
# https://github.com/aboutcode-org/univers/issues/204
# These schemes used to accept the empty string and then sort it as the
# minimum version (Maven, Rubygems), raise on comparison (Nuget), or
# both (Conan), silently corrupting downstream range logic.
import pytest

from univers.versions import ConanVersion
from univers.versions import InvalidVersion

for version_class in (
Version,
MavenVersion,
NugetVersion,
RubygemsVersion,
ConanVersion,
SemverVersion,
PypiVersion,
):
with pytest.raises(InvalidVersion):
version_class("")