Skip to content

Commit 911ac17

Browse files
committed
Make ShortVersionParser.TryParse fail for versions with more than 3 segments
1 parent b7760e2 commit 911ac17

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

GitFlowVersion/ShortVersionParser.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public static bool TryParse(string versionString, out int major, out int minor,
3131
minor = 0;
3232
patch = 0;
3333
var strings = versionString.Split('.');
34-
if (strings.Length < 2)
34+
if (strings.Length < 2 || strings.Length > 3)
3535
{
3636
return false;
3737
}
@@ -45,7 +45,7 @@ public static bool TryParse(string versionString, out int major, out int minor,
4545
return false;
4646
}
4747

48-
if (strings.Length >= 3)
48+
if (strings.Length == 3)
4949
{
5050
if (!int.TryParse(strings[2], out patch))
5151
{

Tests/ShortVersionParserTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ public void Major_minorTry()
5555
result = ShortVersionParser.TryParseMajorMinor("1.2.0-alpha1", out major, out minor);
5656
Assert.IsFalse(result);
5757

58+
result = ShortVersionParser.TryParseMajorMinor("1.2.0.0", out major, out minor);
59+
Assert.IsFalse(result);
60+
61+
result = ShortVersionParser.TryParseMajorMinor("1.2.0.1", out major, out minor);
62+
Assert.IsFalse(result);
63+
5864
result = ShortVersionParser.TryParseMajorMinor("1.2", out major, out minor);
5965
Assert.IsTrue(result);
6066

0 commit comments

Comments
 (0)