From 07c325430e9eafe35e09cd7d6261f26250d47f09 Mon Sep 17 00:00:00 2001 From: Matthias Glauch Date: Thu, 27 May 2021 23:08:03 +0200 Subject: [PATCH] fixed SemVer regex (major number was optional) and added test for the issue caused by the wrong regex --- .../VersionCalculation/SemanticVersionTests.cs | 5 +++-- .../VersionCalculation/SemanticVersioning/SemanticVersion.cs | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/GitVersion.Core.Tests/VersionCalculation/SemanticVersionTests.cs b/src/GitVersion.Core.Tests/VersionCalculation/SemanticVersionTests.cs index 1637227ffd..ef8a8f79c8 100644 --- a/src/GitVersion.Core.Tests/VersionCalculation/SemanticVersionTests.cs +++ b/src/GitVersion.Core.Tests/VersionCalculation/SemanticVersionTests.cs @@ -57,9 +57,10 @@ public void ValidateVersionParsing( [TestCase("someText")] [TestCase("some-T-ext")] - public void ValidateInvalidVersionParsing(string versionString) + [TestCase("v.1.2.3", "v")] + public void ValidateInvalidVersionParsing(string versionString, string tagPrefixRegex = null) { - Assert.IsFalse(SemanticVersion.TryParse(versionString, null, out _), "TryParse Result"); + Assert.IsFalse(SemanticVersion.TryParse(versionString, tagPrefixRegex, out _), "TryParse Result"); } [Test] diff --git a/src/GitVersion.Core/VersionCalculation/SemanticVersioning/SemanticVersion.cs b/src/GitVersion.Core/VersionCalculation/SemanticVersioning/SemanticVersion.cs index 3975a634f8..6b96d966d9 100644 --- a/src/GitVersion.Core/VersionCalculation/SemanticVersioning/SemanticVersion.cs +++ b/src/GitVersion.Core/VersionCalculation/SemanticVersioning/SemanticVersion.cs @@ -8,7 +8,7 @@ public class SemanticVersion : IFormattable, IComparable private static SemanticVersion Empty = new SemanticVersion(); private static readonly Regex ParseSemVer = new Regex( - @"^(?(?\d+)?(\.(?\d+))?(\.(?\d+))?)(\.(?\d+))?(-(?[^\+]*))?(\+(?.*))?$", + @"^(?(?\d+)(\.(?\d+))?(\.(?\d+))?)(\.(?\d+))?(-(?[^\+]*))?(\+(?.*))?$", RegexOptions.Compiled); public int Major;