Do not allow creation of VersionRange with empty constraints - #210
Open
MGpromax wants to merge 1 commit into
Open
Do not allow creation of VersionRange with empty constraints#210MGpromax wants to merge 1 commit into
MGpromax wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #203
VersionRangesubclasses could be constructed directly with an empty constraints sequence and then serialized to an invalid vers string such asvers: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 raisesValueErrorwhenconstraintsis empty.Two consequences handled in this PR:
from_nativedata-driven test cases expected the empty native range""to producevers:conan/, i.e. the test data encoded the invalid output. Those cases now expect aValueError.SchemaDrivenVersTest) had no way to express an expected failure, so it gains an optionalexpected_errorfield 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, andfrom_string("vers:apache/").Test suite:
7271 passed; the 2 failures intest_semver_version/test_enhanced_semantic_versionare pre-existing on a clean checkout with the same environment (also noted in #209) and unrelated to this change.