diff --git a/source/Octopus.Versioning.Tests/Octopus/OctopusVersionTests.cs b/source/Octopus.Versioning.Tests/Octopus/OctopusVersionTests.cs index d7fec7e..010c575 100644 --- a/source/Octopus.Versioning.Tests/Octopus/OctopusVersionTests.cs +++ b/source/Octopus.Versioning.Tests/Octopus/OctopusVersionTests.cs @@ -1081,7 +1081,25 @@ public void TestOriginalStringIsTheSame(string version) 0, 0, "123ABC.123")] - public void TestVersionNumbersAreDelimited(string inputVersion, int major, int minor, int patch, int revision, string release) + [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); diff --git a/source/Octopus.Versioning/Octopus/OctopusVersionParser.cs b/source/Octopus.Versioning/Octopus/OctopusVersionParser.cs index ea51077..83cd361 100644 --- a/source/Octopus.Versioning/Octopus/OctopusVersionParser.cs +++ b/source/Octopus.Versioning/Octopus/OctopusVersionParser.cs @@ -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+\b)\s*" + + @$"\s*(?<{Major}>\d+(?=\b|_))\s*" + // Get the minor version number, delimited by a period - @$"(?:\.\s*(?<{Minor}>\d+\b)\s*)?" + + @$"(?:\.\s*(?<{Minor}>\d+(?=\b|_))\s*)?" + // Get the patch version number, delimited by a period - @$"(?:\.\s*(?<{Patch}>\d+\b)\s*)?" + + @$"(?:\.\s*(?<{Patch}>\d+(?=\b|_))\s*)?" + // Get the revision version number, delimited by a period - @$"(?:\.\s*(?<{Revision}>\d+\b)\s*)?)?" + + @$"(?:\.\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