diff --git a/MavenNet.Tests/MavenNet.Tests.csproj b/MavenNet.Tests/MavenNet.Tests.csproj index bac2148..1747cb9 100644 --- a/MavenNet.Tests/MavenNet.Tests.csproj +++ b/MavenNet.Tests/MavenNet.Tests.csproj @@ -1,13 +1,13 @@ - netcoreapp3.1 + net8.0 - - - runtime; build; native; contentfiles; analyzers; buildtransitive + + + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/MavenNet.Tests/MavenVersioningTests.cs b/MavenNet.Tests/MavenVersioningTests.cs index 62e43f9..64407f3 100644 --- a/MavenNet.Tests/MavenVersioningTests.cs +++ b/MavenNet.Tests/MavenVersioningTests.cs @@ -18,6 +18,14 @@ public class MavenVersioningTests [InlineData("(,1.0],[1.2,)", "1.2", true)] [InlineData("(,1.0],[1.2,)", "1.3", true)] [InlineData("(,1.0],[1.2,)", "1.1", false)] + [InlineData("(,1.0],[2.2,)", "1.0.1.262e11d", false)] + [InlineData("(,0.8],[2.2,)", "0.11.1.647c3c2", false)] + [InlineData("(,0.8],[2.2,)", "0.11.1.3c786d2", false)] + [InlineData("(,0.8],[2.2,)", "0.10.1.2e8fe11", false)] + [InlineData("(,0.8],[2.2,)", "0.10.1.e92f734", false)] + [InlineData("(,0.8],[2.2,)", "0.10.1.d22d4de", false)] + [InlineData("(,0.8],[2.2,)", "0.9.3.545a756", false)] + [InlineData("(,0.8],[2.2,)", "0.9.3.a319893", false)] public void Satisfy_Versions(string range, string version, bool satisfies) { var mvr = new MavenVersionRange(range); diff --git a/MavenNet/MavenNet.csproj b/MavenNet/MavenNet.csproj index 3f6760f..6d30ebf 100644 --- a/MavenNet/MavenNet.csproj +++ b/MavenNet/MavenNet.csproj @@ -30,7 +30,7 @@ - - + + diff --git a/MavenNet/MavenVersionRange.cs b/MavenNet/MavenVersionRange.cs index b441c5a..d73d0cd 100644 --- a/MavenNet/MavenVersionRange.cs +++ b/MavenNet/MavenVersionRange.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Text.RegularExpressions; @@ -16,7 +17,40 @@ public MavenVersionRange(string value) public bool Satisfies(string version) { - var nugetVersion = NuGet.Versioning.NuGetVersion.Parse(version); + var nugetVersion = default(NuGet.Versioning.NuGetVersion); + + try + { + nugetVersion = NuGet.Versioning.NuGetVersion.Parse(version); + } + catch (Exception e) + { + if (e is System.ArgumentException && e.Message.Contains(" is not a valid version string.")) + { + try + { + int idx = version.LastIndexOf('.'); + // creating valid SemVer from invalid Maven + string semver = version.Substring(0, idx); + nugetVersion = NuGet.Versioning.NuGetVersion.Parse(semver); + string release_textual = version.Substring(idx + 1, version.Length - idx - 1); + try + { + int release_numeric = int.Parse(release_textual, NumberStyles.HexNumber); + nugetVersion = NuGet.Versioning.NuGetVersion.Parse($"{semver}.{release_numeric}"); + } + catch (Exception exception) + { + nugetVersion = NuGet.Versioning.NuGetVersion.Parse($"{semver}+{release_textual}"); + } + } + catch (Exception ei) + { + Console.WriteLine(ei); + throw; + } + } + } var v = Regex.Replace(Value, "\\s", "");