From 444364f418f567405bbd6ba6277432a42c89357d Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 21 Dec 2016 13:33:59 -0500 Subject: fix version pre-release tags not consistently normalised (#195) --- src/StardewModdingAPI/SemanticVersion.cs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src/StardewModdingAPI') diff --git a/src/StardewModdingAPI/SemanticVersion.cs b/src/StardewModdingAPI/SemanticVersion.cs index cf435aaa..9694375e 100644 --- a/src/StardewModdingAPI/SemanticVersion.cs +++ b/src/StardewModdingAPI/SemanticVersion.cs @@ -13,6 +13,9 @@ namespace StardewModdingAPI /// Derived from https://github.com/maxhauser/semver. private static readonly Regex Regex = new Regex(@"^(?\d+)(\.(?\d+))?(\.(?\d+))?(?.*)$", RegexOptions.CultureInvariant | RegexOptions.ExplicitCapture); + /// The backing field for . + private string _build; + /********* ** Accessors @@ -27,7 +30,11 @@ namespace StardewModdingAPI public int PatchVersion { get; set; } /// An optional build tag. - public string Build { get; set; } + public string Build + { + get { return this._build; } + set { this._build = this.GetNormalisedTag(value); } + } /********* @@ -124,7 +131,7 @@ namespace StardewModdingAPI : $"{this.MajorVersion}.{this.MinorVersion}"; // tag - string tag = this.GetNormalisedTag(this.Build); + string tag = this.Build; if (tag != null) result += $"-{tag}"; return result; @@ -145,7 +152,7 @@ namespace StardewModdingAPI this.MajorVersion = int.Parse(match.Groups["major"].Value); this.MinorVersion = match.Groups["minor"].Success ? int.Parse(match.Groups["minor"].Value) : 0; this.PatchVersion = match.Groups["patch"].Success ? int.Parse(match.Groups["patch"].Value) : 0; - this.Build = (match.Groups["build"].Success ? match.Groups["build"].Value : "").Trim(' ', '-', '.'); + this.Build = match.Groups["build"].Success ? match.Groups["build"].Value : null; } /// Get a normalised build tag. @@ -153,8 +160,10 @@ namespace StardewModdingAPI private string GetNormalisedTag(string tag) { tag = tag?.Trim().Trim('-', '.'); - if (string.IsNullOrWhiteSpace(tag) || tag == "0") + if (string.IsNullOrWhiteSpace(tag)) return null; + if (tag == "0") + return null; // from incorrect examples in old SMAPI documentation return tag; } } -- cgit