Skip to content

Do not allow creation of VersionRange with empty constraints - #210

Open
MGpromax wants to merge 1 commit into
aboutcode-org:mainfrom
MGpromax:reject-empty-version-range
Open

Do not allow creation of VersionRange with empty constraints#210
MGpromax wants to merge 1 commit into
aboutcode-org:mainfrom
MGpromax:reject-empty-version-range

Conversation

@MGpromax

Copy link
Copy Markdown

Fixes #203

VersionRange subclasses could be constructed directly with an empty constraints sequence and then serialized to an invalid vers string such as vers:apache/ -- from_string() already rejects those strings, so direct construction was the only way to produce them (as in the issue's reproducer).

__attrs_post_init__ now raises ValueError when constraints is empty.

Two consequences handled in this PR:

  • Four Conan from_native data-driven test cases expected the empty native range "" to produce vers:conan/, i.e. the test data encoded the invalid output. Those cases now expect a ValueError.
  • The schema-driven test harness (SchemaDrivenVersTest) had no way to express an expected failure, so it gains an optional expected_error field naming the exception class; cases without it behave exactly as before.

Also added a direct regression test constructing VersionRange(constraints=[]), a subclass with empty constraints, and from_string("vers:apache/").

Test suite: 7271 passed; the 2 failures in test_semver_version / test_enhanced_semantic_version are pre-existing on a clean checkout with the same environment (also noted in #209) and unrelated to this change.

A VersionRange constructed directly with an empty constraints
sequence serialized to an invalid vers string such as 'vers:apache/'
with no constraint. from_string() already rejects such strings, so
only direct construction could produce these invalid ranges.

Raise ValueError from __attrs_post_init__ when constraints is empty.
The four Conan from_native test cases that expected an empty native
range to produce 'vers:conan/' now expect a ValueError instead, and
the schema-driven test harness gains an optional expected_error field
to express that.

Fixes aboutcode-org#203

Signed-off-by: Manoj Gowda <manojgowdabs18@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Do not allow creation of VersionRange with empty constraint

1 participant