Skip to content

Commit

Permalink
fix: versions prefixed with 'v' are parsed in strict mode (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
anatawa12 authored Oct 16, 2023
1 parent ebeeab6 commit a1187b3
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 67 deletions.
2 changes: 1 addition & 1 deletion src/SemanticVersioning/Version.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class Version : IComparable<Version>, IComparable, IEquatable<Version>
public bool IsPreRelease { get { return !string.IsNullOrEmpty(_preRelease); } }

private static Regex strictRegex = new Regex(@"^
\s*v?
\s*
([0-9]|[1-9][0-9]+) # major version
\.
([0-9]|[1-9][0-9]+) # minor version
Expand Down
8 changes: 4 additions & 4 deletions test/SemanticVersioning.Tests/AdvancedRanges.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public void TestHyphenRanges(string range, string[] comparatorStrings)
[InlineData(">=*", "0.2.4")]
[InlineData("", "1.0.0")]
[InlineData("*", "1.2.3")]
[InlineData("*", "v1.2.3")]
[InlineData("*", "1.2.3")]
[InlineData(">=1.0.0", "1.0.0")]
[InlineData(">=1.0.0", "1.0.1")]
[InlineData(">=1.0.0", "1.1.0")]
Expand All @@ -138,7 +138,7 @@ public void TestHyphenRanges(string range, string[] comparatorStrings)
[InlineData("<= 2.0.0", "0.2.9")]
[InlineData("< 2.0.0", "1.9999.9999")]
[InlineData("<\t2.0.0", "0.2.9")]
[InlineData(">=0.1.97", "v0.1.97")]
[InlineData(">=0.1.97", "0.1.97")]
[InlineData(">=0.1.97", "0.1.97")]
[InlineData("0.1.20 || 1.2.4", "1.2.4")]
[InlineData(">=0.2.3 || <0.0.1", "0.0.0")]
Expand Down Expand Up @@ -228,7 +228,7 @@ public void SatisfiedRanges(string rangeString, string versionString)
[InlineData("<=2.0.0", "2.2.9", false)]
[InlineData("<2.0.0", "2.9999.9999", false)]
[InlineData("<2.0.0", "2.2.9", false)]
[InlineData(">=0.1.97", "v0.1.93", false)]
[InlineData(">=0.1.97", "0.1.93", false)]
[InlineData(">=0.1.97", "0.1.93", false)]
[InlineData("0.1.20 || 1.2.4", "1.2.3", false)]
[InlineData(">=0.2.3 || <0.0.1", "0.0.3", false)]
Expand Down Expand Up @@ -263,7 +263,7 @@ public void SatisfiedRanges(string rangeString, string versionString)
[InlineData("^1.2.3", "1.2.2", false)]
[InlineData("^1.2", "1.1.9", false)]
[InlineData("^1.2.3", "2.0.0-pre", false)]
[InlineData("*", "v1.2.3-foo", false)]
[InlineData("*", "1.2.3-foo", false)]
public void UnsatisfiedRanges(string rangeString, string versionString, bool loose)
{
var range = new Range(rangeString, loose);
Expand Down
12 changes: 6 additions & 6 deletions test/SemanticVersioning.Tests/ParseMajorMinorPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ public class ParseMajorMinorPatch
[InlineData(" 1.2.3 ", 1, false)]
[InlineData(" 2.2.3-4 ", 2, false)]
[InlineData(" 3.2.3-pre ", 3, false)]
[InlineData("v5.2.3", 5, false)]
[InlineData(" v8.2.3 ", 8, false)]
[InlineData("\t13.2.3", 13, false)]
[InlineData(" v8.2.3 ", 8, true)]
[InlineData("v5.2.3", 5, true)]
[InlineData("=21.2.3", 21, true)]
[InlineData("v=34.2.3", 34, true)]
public void ParseMajorVersion(string versionString, int majorVersion, bool loose)
Expand All @@ -26,9 +26,9 @@ public void ParseMajorVersion(string versionString, int majorVersion, bool loose
[InlineData(" 1.2.3 ", 2, false)]
[InlineData(" 2.2.3-4 ", 2, false)]
[InlineData(" 3.2.3-pre ", 2, false)]
[InlineData("v5.2.3", 2, false)]
[InlineData(" v8.2.3 ", 2, false)]
[InlineData("\t13.2.3", 2, false)]
[InlineData(" v8.2.3 ", 2, true)]
[InlineData("v5.2.3", 2, true)]
[InlineData("=21.2.3", 2, true)]
[InlineData("v=34.2.3", 2, true)]
public void ParseMinorVersion(string versionString, int minorVersion, bool loose)
Expand All @@ -42,9 +42,9 @@ public void ParseMinorVersion(string versionString, int minorVersion, bool loose
[InlineData(" 1.2.3 ", 3, false)]
[InlineData(" 2.2.3-4 ", 3, false)]
[InlineData(" 3.2.3-pre ", 3, false)]
[InlineData("v5.2.3", 3, false)]
[InlineData(" v8.2.3 ", 3, false)]
[InlineData("\t13.2.3", 3, false)]
[InlineData(" v8.2.3 ", 3, true)]
[InlineData("v5.2.3", 3, true)]
[InlineData("=21.2.3", 3, true)]
[InlineData("v=34.2.3", 3, true)]
public void ParsePatchVersion(string versionString, int patchVersion, bool loose)
Expand Down
14 changes: 7 additions & 7 deletions test/SemanticVersioning.Tests/SimpleRanges.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ public void TestMaxSatisfying()
public void TestStringMaxSatisfying()
{
var versions = new [] {
"=1.2.7",
"v1.2.8",
"v1.2.99",
"=1.2.6",
"v1.3.0",
"v1.1.0",
"1.2.7",
"1.2.8",
"1.2.99",
"1.2.6",
"1.3.0",
"1.1.0",
};
var range = new Range(">=1.2.7 <1.3.0");
Assert.Equal("v1.2.99", range.MaxSatisfying(versions));
Assert.Equal("1.2.99", range.MaxSatisfying(versions));
}

[Fact]
Expand Down
50 changes: 25 additions & 25 deletions test/SemanticVersioning.Tests/StaticRangeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,32 @@ public void TestMaxSatisfying()
{
var versions = new [] {
"1.2.7",
"v1.2.8",
"v1.2.99",
"1.2.8",
"1.2.99",
"1.2.6",
"v1.3.0",
"v1.1.0",
"1.3.0",
"1.1.0",
};
var max = Range.MaxSatisfying(">=1.2.7 <1.3.0", versions);
Assert.Equal("v1.2.99", max);
Assert.Equal("1.2.99", max);
}

[Fact]
public void TestSatisfying()
{
var versions = new [] {
"1.2.7",
"v1.2.8",
"v1.2.99",
"1.2.8",
"1.2.99",
"1.2.6",
"v1.3.0",
"v1.1.0",
"1.3.0",
"1.1.0",
};
var satisfying = Range.Satisfying(">=1.2.7 <1.3.0", versions).ToArray();
Assert.Equal(3, satisfying.Count());
Assert.Contains("1.2.7", satisfying);
Assert.Contains("v1.2.8", satisfying);
Assert.Contains("v1.2.99", satisfying);
Assert.Contains("1.2.8", satisfying);
Assert.Contains("1.2.99", satisfying);
}

[Theory]
Expand All @@ -53,35 +53,35 @@ public void TestMaxSatisfyingWithIncludePreRelease()
{
var versions = new [] {
"1.2.7",
"v1.2.8",
"v1.2.98",
"v1.2.99-alpha.1",
"1.2.8",
"1.2.98",
"1.2.99-alpha.1",
"1.2.6",
"v1.3.0",
"v1.1.0",
"1.3.0",
"1.1.0",
};
var max = Range.MaxSatisfying(">=1.2.7 <1.3.0", versions, includePrerelease: true);
Assert.Equal("v1.2.99-alpha.1", max);
Assert.Equal("1.2.99-alpha.1", max);
}

[Fact]
public void TestSatisfyingWithIncludePreRelease()
{
var versions = new [] {
"1.2.7",
"v1.2.8-beta.2",
"v1.2.98",
"v1.2.99-alpha.1",
"1.2.8-beta.2",
"1.2.98",
"1.2.99-alpha.1",
"1.2.6",
"v1.3.0",
"v1.1.0",
"1.3.0",
"1.1.0",
};
var satisfying = Range.Satisfying(">=1.2.7 <1.3.0", versions, includePrerelease: true).ToArray();
Assert.Equal(4, satisfying.Count());
Assert.Contains("1.2.7", satisfying);
Assert.Contains("v1.2.98", satisfying);
Assert.Contains("v1.2.8-beta.2", satisfying);
Assert.Contains("v1.2.99-alpha.1", satisfying);
Assert.Contains("1.2.98", satisfying);
Assert.Contains("1.2.8-beta.2", satisfying);
Assert.Contains("1.2.99-alpha.1", satisfying);
}

[Theory]
Expand Down
48 changes: 24 additions & 24 deletions test/SemanticVersioning.Tests/VersionComparison.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,18 +157,18 @@ public void CompareToDifferentType()
[InlineData("0.10.0", "0.9.0")]
[InlineData("0.99.0", "0.10.0")]
[InlineData("2.0.0", "1.2.3")]
[InlineData("v0.0.0", "0.0.0-foo")]
[InlineData("v0.0.1", "0.0.0")]
[InlineData("v1.0.0", "0.9.9")]
[InlineData("v0.10.0", "0.9.0")]
[InlineData("v0.99.0", "0.10.0")]
[InlineData("v2.0.0", "1.2.3")]
[InlineData("0.0.0", "v0.0.0-foo")]
[InlineData("0.0.1", "v0.0.0")]
[InlineData("1.0.0", "v0.9.9")]
[InlineData("0.10.0", "v0.9.0")]
[InlineData("0.99.0", "v0.10.0")]
[InlineData("2.0.0", "v1.2.3")]
[InlineData("0.0.0", "0.0.0-foo")]
[InlineData("0.0.1", "0.0.0")]
[InlineData("1.0.0", "0.9.9")]
[InlineData("0.10.0", "0.9.0")]
[InlineData("0.99.0", "0.10.0")]
[InlineData("2.0.0", "1.2.3")]
[InlineData("0.0.0", "0.0.0-foo")]
[InlineData("0.0.1", "0.0.0")]
[InlineData("1.0.0", "0.9.9")]
[InlineData("0.10.0", "0.9.0")]
[InlineData("0.99.0", "0.10.0")]
[InlineData("2.0.0", "1.2.3")]
[InlineData("1.2.3", "1.2.3-asdf")]
[InlineData("1.2.3", "1.2.3-4")]
[InlineData("1.2.3", "1.2.3-4-foo")]
Expand Down Expand Up @@ -197,43 +197,43 @@ public void Comparisons(string v0s, string v1s)

// Equality tests from npm/node-semver
[Theory]
[InlineData("1.2.3", "v1.2.3", false)]
[InlineData("1.2.3", "1.2.3", false)]
[InlineData("1.2.3", "=1.2.3", true)]
[InlineData("1.2.3", "v 1.2.3", true)]
[InlineData("1.2.3", " 1.2.3", true)]
[InlineData("1.2.3", "= 1.2.3", true)]
[InlineData("1.2.3", " v1.2.3", false)]
[InlineData("1.2.3", " 1.2.3", false)]
[InlineData("1.2.3", " =1.2.3", true)]
[InlineData("1.2.3", " v 1.2.3", true)]
[InlineData("1.2.3", " = 1.2.3", true)]
[InlineData("1.2.3-0", "v1.2.3-0", false)]
[InlineData("1.2.3-0", "1.2.3-0", false)]
[InlineData("1.2.3-0", "=1.2.3-0", true)]
[InlineData("1.2.3-0", "v 1.2.3-0", true)]
[InlineData("1.2.3-0", " 1.2.3-0", true)]
[InlineData("1.2.3-0", "= 1.2.3-0", true)]
[InlineData("1.2.3-0", " v1.2.3-0", false)]
[InlineData("1.2.3-0", " =1.2.3-0", true)]
[InlineData("1.2.3-0", " v 1.2.3-0", true)]
[InlineData("1.2.3-0", " = 1.2.3-0", true)]
[InlineData("1.2.3-1", "v1.2.3-1", false)]
[InlineData("1.2.3-1", "1.2.3-1", false)]
[InlineData("1.2.3-1", "=1.2.3-1", true)]
[InlineData("1.2.3-1", "v 1.2.3-1", true)]
[InlineData("1.2.3-1", " 1.2.3-1", true)]
[InlineData("1.2.3-1", "= 1.2.3-1", true)]
[InlineData("1.2.3-1", " v1.2.3-1", false)]
[InlineData("1.2.3-1", " 1.2.3-1", false)]
[InlineData("1.2.3-1", " =1.2.3-1", true)]
[InlineData("1.2.3-1", " v 1.2.3-1", true)]
[InlineData("1.2.3-1", " = 1.2.3-1", true)]
[InlineData("1.2.3-beta", "v1.2.3-beta", false)]
[InlineData("1.2.3-beta", "1.2.3-beta", false)]
[InlineData("1.2.3-beta", "=1.2.3-beta", true)]
[InlineData("1.2.3-beta", "v 1.2.3-beta", true)]
[InlineData("1.2.3-beta", " 1.2.3-beta", true)]
[InlineData("1.2.3-beta", "= 1.2.3-beta", true)]
[InlineData("1.2.3-beta", " v1.2.3-beta", false)]
[InlineData("1.2.3-beta", " 1.2.3-beta", false)]
[InlineData("1.2.3-beta", " =1.2.3-beta", true)]
[InlineData("1.2.3-beta", " v 1.2.3-beta", true)]
[InlineData("1.2.3-beta", " = 1.2.3-beta", true)]
[InlineData("1.2.3-beta+build", " = 1.2.3-beta+otherbuild", true)]
[InlineData("1.2.3+build", " = 1.2.3+otherbuild", true)]
[InlineData("1.2.3-beta+build", "1.2.3-beta+otherbuild", false)]
[InlineData("1.2.3+build", "1.2.3+otherbuild", false)]
[InlineData(" v1.2.3+build", "1.2.3+otherbuild", false)]
[InlineData(" 1.2.3+build", "1.2.3+otherbuild", false)]
public void Equality(string v0s, string v1s, bool loose)
{
var v0 = new Version(v0s, false);
Expand Down

0 comments on commit a1187b3

Please sign in to comment.