Skip to content

Commit

Permalink
Regex word boundary accepts _ as a word character so changing it to a…
Browse files Browse the repository at this point in the history
… homemade word boundary that handles _ characters
  • Loading branch information
tleed5 committed Jan 4, 2024
1 parent 79b1c99 commit f6f7c2e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
20 changes: 19 additions & 1 deletion source/Octopus.Versioning.Tests/Octopus/OctopusVersionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 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+\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
Expand Down

0 comments on commit f6f7c2e

Please sign in to comment.