Skip to content

Commit

Permalink
Do not allow leading and trailing whitespace in strict mode (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
anatawa12 authored Oct 24, 2023
1 parent 620dc55 commit 949d401
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 19 deletions.
2 changes: 0 additions & 2 deletions src/SemanticVersioning/Version.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,13 @@ public class Version : IComparable<Version>, IComparable, IEquatable<Version>
public bool IsPreRelease { get { return !string.IsNullOrEmpty(_preRelease); } }

private static Regex strictRegex = new Regex(@"^
\s*
([0-9]|[1-9][0-9]+) # major version
\.
([0-9]|[1-9][0-9]+) # minor version
\.
([0-9]|[1-9][0-9]+) # patch version
(\-([0-9A-Za-z\-\.]+))? # pre-release version
(\+([0-9A-Za-z\-\.]+))? # build metadata
\s*
$",
RegexOptions.IgnorePatternWhitespace);

Expand Down
21 changes: 9 additions & 12 deletions test/SemanticVersioning.Tests/ParseMajorMinorPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ public class ParseMajorMinorPatch
{
[Theory]
[InlineData("1.2.3", 1, false)]
[InlineData(" 1.2.3 ", 1, false)]
[InlineData(" 2.2.3-4 ", 2, false)]
[InlineData(" 3.2.3-pre ", 3, false)]
[InlineData("\t13.2.3", 13, false)]
[InlineData("2.2.3-4", 2, false)]
[InlineData("3.2.3-pre", 3, false)]
[InlineData("\t13.2.3", 13, true)]
[InlineData(" v8.2.3 ", 8, true)]
[InlineData("v5.2.3", 5, true)]
[InlineData("=21.2.3", 21, true)]
Expand All @@ -23,10 +22,9 @@ public void ParseMajorVersion(string versionString, int majorVersion, bool loose

[Theory]
[InlineData("1.2.3", 2, false)]
[InlineData(" 1.2.3 ", 2, false)]
[InlineData(" 2.2.3-4 ", 2, false)]
[InlineData(" 3.2.3-pre ", 2, false)]
[InlineData("\t13.2.3", 2, false)]
[InlineData("2.2.3-4", 2, false)]
[InlineData("3.2.3-pre", 2, false)]
[InlineData("\t13.2.3", 2, true)]
[InlineData(" v8.2.3 ", 2, true)]
[InlineData("v5.2.3", 2, true)]
[InlineData("=21.2.3", 2, true)]
Expand All @@ -39,10 +37,9 @@ public void ParseMinorVersion(string versionString, int minorVersion, bool loose

[Theory]
[InlineData("1.2.3", 3, false)]
[InlineData(" 1.2.3 ", 3, false)]
[InlineData(" 2.2.3-4 ", 3, false)]
[InlineData(" 3.2.3-pre ", 3, false)]
[InlineData("\t13.2.3", 3, false)]
[InlineData("2.2.3-4", 3, false)]
[InlineData("3.2.3-pre", 3, false)]
[InlineData("13.2.3", 3, false)]
[InlineData(" v8.2.3 ", 3, true)]
[InlineData("v5.2.3", 3, true)]
[InlineData("=21.2.3", 3, true)]
Expand Down
5 changes: 0 additions & 5 deletions test/SemanticVersioning.Tests/VersionComparison.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,39 +189,34 @@ public void Comparisons(string v0s, string v1s)
[InlineData("1.2.3", "=1.2.3", true)]
[InlineData("1.2.3", " 1.2.3", true)]
[InlineData("1.2.3", "= 1.2.3", true)]
[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", "1.2.3-0", false)]
[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", "= 1.2.3-0", true)]
[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-1", "1.2.3-1", false)]
[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", "= 1.2.3-1", true)]
[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", "1.2.3-beta", false)]
[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", "= 1.2.3-beta", true)]
[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(" 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 949d401

Please sign in to comment.