Skip to content

Commit

Permalink
Merge pull request #2712 from mglochsen/feature/2711-fix-format-excep…
Browse files Browse the repository at this point in the history
…tion

Fixed SemVer regex (major number was optional) and added test
  • Loading branch information
asbjornu authored May 27, 2021
2 parents e901353 + 07c3254 commit 32fe901
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class SemanticVersion : IFormattable, IComparable<SemanticVersion>
private static SemanticVersion Empty = new SemanticVersion();

private static readonly Regex ParseSemVer = new Regex(
@"^(?<SemVer>(?<Major>\d+)?(\.(?<Minor>\d+))?(\.(?<Patch>\d+))?)(\.(?<FourthPart>\d+))?(-(?<Tag>[^\+]*))?(\+(?<BuildMetaData>.*))?$",
@"^(?<SemVer>(?<Major>\d+)(\.(?<Minor>\d+))?(\.(?<Patch>\d+))?)(\.(?<FourthPart>\d+))?(-(?<Tag>[^\+]*))?(\+(?<BuildMetaData>.*))?$",
RegexOptions.Compiled);

public int Major;
Expand Down

0 comments on commit 32fe901

Please sign in to comment.