Skip to content

Reject empty strings in Maven, Nuget, Rubygems and Conan versions - #209

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

Reject empty strings in Maven, Nuget, Rubygems and Conan versions#209
MGpromax wants to merge 1 commit into
aboutcode-org:mainfrom
MGpromax:reject-empty-versions

Conversation

@MGpromax

Copy link
Copy Markdown

Fixes #204

MavenVersion, NugetVersion, RubygemsVersion -- and also ConanVersion, which the issue did not list but has the same hole (found by auditing every Version subclass with an empty string) -- accepted "" because their is_valid() overrides only try to parse the value and the underlying parsers accept empty input. The base Version.is_valid() docstring already promises that the empty string is invalid; the overrides just never consulted it.

The fix makes each override check super().is_valid(string) first, so all four now raise InvalidVersion("") like SemverVersion and PypiVersion do, instead of the three different silent behaviors described in the issue (sorts-as-minimum, TypeError on comparison, or both). DebianVersion shares the same try/except body and gets the same guard for consistency, although its parser already rejected empty input.

Added a regression test covering the fixed classes plus SemverVersion/PypiVersion as canaries.

Test suite: 7272 passed; the 2 failures in test_semver_version / test_enhanced_semantic_version (semver build-metadata ordering) are pre-existing on a clean checkout with the same environment and unrelated to this change.

MavenVersion, NugetVersion, RubygemsVersion and ConanVersion accepted
the empty string because their is_valid() overrides only tried to
parse the value, and the underlying parsers accept empty input. An
accepted empty version then sorted below every real version (Maven,
Rubygems), raised TypeError on comparison (Nuget), or both (Conan),
silently corrupting downstream range logic instead of failing.

Make the overrides honor the base Version.is_valid() contract, which
already documents that the empty string is invalid, by checking
super().is_valid() first. DebianVersion gets the same guard for
consistency although its parser already rejected empty input.

Fixes aboutcode-org#204

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.

Empty string accepted as a valid version in Maven/NuGet/RubyGems, and sorts as minimum

1 participant