Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated OctopusVersionParser regex to ensure delimiters between version numbers #73

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 62 additions & 28 deletions source/Octopus.Versioning.Tests/Octopus/OctopusVersionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -683,32 +683,6 @@ public void TestMavenVersions(string version,
"0",
"alpha",
"")]
[TestCase("1_0_alpha",
1,
0,
0,
0,
0,
0,
0,
"",
"0_alpha",
"0",
"alpha",
"")]
[TestCase("1_0alpha",
1,
0,
0,
0,
0,
0,
0,
"",
"0alpha",
"0alpha",
"",
"")]
Comment on lines -686 to -711
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like these tests are checking if the maven version parser and octopus version parser returns the same result for certain version strings, these test cases that I removed no longer return the same result between the two version parsers.

That said I think the maven parser suffers the same issue where it doesn't require a delimiter between the major version and the rest of the version string

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be worth running this one by @mcasperson who was involved in adding the maven support

[TestCase("1.0a1-SNAPSHOT",
1,
0,
Expand All @@ -718,8 +692,8 @@ public void TestMavenVersions(string version,
0,
0,
"",
"a1-SNAPSHOT",
"a1",
"0a1-SNAPSHOT",
"0a1",
"SNAPSHOT",
"")]
[TestCase("1-2.3-SNAPSHOT",
Expand Down Expand Up @@ -1076,12 +1050,72 @@ public void TestOriginalStringIsTheSame(string version)
Assert.AreEqual(octoVersion.OriginalString, semanticVersion.OriginalString);
}

[Test]
[TestCase("123",
123,
0,
0,
0,
"")]
[TestCase("123ABC",
0,
0,
0,
0,
"123ABC")]
[TestCase("123ABC-CBC",
0,
0,
0,
0,
"123ABC-CBC")]
[TestCase("123.123.123.123",
123,
123,
123,
123,
"")]
[TestCase("123.123ABC.123",
123,
0,
0,
0,
"123ABC.123")]
[TestCase("1.0_prerelease",
1,
0,
0,
0,
"prerelease")]
[TestCase("V1.0",
1,
0,
0,
0,
"")]
[TestCase("v1.0",
1,
0,
0,
0,
"")]
public void TestVersionNumberVariations(string inputVersion, int major, int minor, int patch, int revision, string release)
{
var parsedVersion = OctopusVersionParser.Parse(inputVersion);
Assert.AreEqual(major, parsedVersion.Major);
Assert.AreEqual(minor, parsedVersion.Minor);
Assert.AreEqual(patch, parsedVersion.Patch);
Assert.AreEqual(revision, parsedVersion.Revision);
Assert.AreEqual(release, parsedVersion.Release);
}

public static string RandomString(int length)
{
const string chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-.\\+";
return new string(Enumerable.Repeat(chars, length)
.Select(s => s[Random.Next(s.Length)])
.ToArray());
}

}
}
14 changes: 7 additions & 7 deletions source/Octopus.Versioning/Octopus/OctopusVersionParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ public class OctopusVersionParser
// Versions can start with an optional V
@$"\s*(?<{Prefix}>v|V)?" +
// Get the major version number
@$"\s*(?<{Major}>\d+)\s*" +
// Get the minor version number, delimited by a period, comma, dash or underscore
@$"(?:\.\s*(?<{Minor}>\d+)\s*)?" +
// Get the patch version number, delimited by a period, comma, dash or underscore
@$"(?:\.\s*(?<{Patch}>\d+)\s*)?" +
// Get the revision version number, delimited by a period, comma, dash or underscore
@$"(?:\.\s*(?<{Revision}>\d+)\s*)?)?" +
@$"\s*(?<{Major}>\d+(?=\b|_))\s*" +
// Get the minor version number, delimited by a period
@$"(?:\.\s*(?<{Minor}>\d+(?=\b|_))\s*)?" +
// Get the patch version number, delimited by a period
@$"(?:\.\s*(?<{Patch}>\d+(?=\b|_))\s*)?" +
// Get the revision version number, delimited by a period
@$"(?:\.\s*(?<{Revision}>\d+(?=\b|_))\s*)?)?" +
// Everything after the last digit and before the plus is the prerelease
@$"(?:[.\-_\\])?(?<{Prerelease}>(?<{PrereleasePrefix}>[A-Za-z0-9]*?)([.\-_\\](?<{PrereleaseCounter}>[A-Za-z0-9.\-_\\]*?)?)?)?" +
// The metadata is everything after the plus
Expand Down
Loading