summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2016-12-21 13:33:59 -0500
committerJesse Plamondon-Willard <github@jplamondonw.com>2016-12-21 13:33:59 -0500
commit444364f418f567405bbd6ba6277432a42c89357d (patch)
tree53b44d3895d5b8f9475813541e04c72ac45c5755
parentc257d705758a23cf28ce2c1f00b6d3d42cd30a26 (diff)
downloadSMAPI-444364f418f567405bbd6ba6277432a42c89357d.tar.gz
SMAPI-444364f418f567405bbd6ba6277432a42c89357d.tar.bz2
SMAPI-444364f418f567405bbd6ba6277432a42c89357d.zip
fix version pre-release tags not consistently normalised (#195)
-rw-r--r--src/StardewModdingAPI/SemanticVersion.cs17
1 files changed, 13 insertions, 4 deletions
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
/// <remarks>Derived from https://github.com/maxhauser/semver.</remarks>
private static readonly Regex Regex = new Regex(@"^(?<major>\d+)(\.(?<minor>\d+))?(\.(?<patch>\d+))?(?<build>.*)$", RegexOptions.CultureInvariant | RegexOptions.ExplicitCapture);
+ /// <summary>The backing field for <see cref="Build"/>.</summary>
+ private string _build;
+
/*********
** Accessors
@@ -27,7 +30,11 @@ namespace StardewModdingAPI
public int PatchVersion { get; set; }
/// <summary>An optional build tag.</summary>
- 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;
}
/// <summary>Get a normalised build tag.</summary>
@@ -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;
}
}