SemVersionRange.Parse("1.x.x") throws an exception
Closed this issue · 2 comments
Describe the bug
SemVersionRange.Parse("1.x.x")
throws an exception, calling the 'x' an invalid character.
SemVersionRange.Parse("1.x.x", SemVersionRangeOptions.OptionalMinorPatch);
also throws.
Unhandled exception. System.FormatException: Minor version contains invalid character 'x' in '1.x.x'.
at Semver.SemVersionRange.Parse(String range, SemVersionRangeOptions options, Int32 maxLength)
at Semver.SemVersionRange.Parse(String range, Int32 maxLength)
at Program.Main()
According to the semver 2 spec, it is valid to use 'x' as a wildcard for semver ranges.
Steps To Reproduce
Code to repro/test the issue: https://dotnetfiddle.net/VI7QmU
Expected behavior
Input 1.x.x
to get parsed in to a range equivalent to ~1
.
Versions(please complete the following information):
- Package Version: x2.3.0
- Framework Version: .NET 8
Additional context
I encountered this issue when using the library to parse Helm chart repository indexes, which sometimes contain versions in the form '2.x.x' in the chart dependencies.
Just tested this using version 3.0.0-beta.2 and the result is the same.
If you want to parse the npm range syntax, use SemVersionRange.ParseNpm
. That seems to be the syntax that you linked to.
SemVersionRange.Parse
does not support x
as a wildcard. This is documented and justified in the Differences from npm Syntax.
There is no official spec for semver ranges. The official spec would be at semver.org. The closest thing there is to a spec is the documentation for the npm package ranges that most tools copy the behavior of. However, it has ambiguities (see Deviations from npm Range Syntax for details). What you linked to is the documentation for someone's Go library for handling semver versions and ranges.