diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2020-02-20 21:32:55 -0500 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2020-02-20 21:32:55 -0500 |
commit | dd27b3bf35d01e4fd0703e47d538bd8cec03652b (patch) | |
tree | 3f3b00c4c1b9cb5fafcfc975e8de7e999b1dc36b /src/SMAPI.Web | |
parent | 6a9bf10a81f4557d44668666117d99440d99d873 (diff) | |
download | SMAPI-dd27b3bf35d01e4fd0703e47d538bd8cec03652b.tar.gz SMAPI-dd27b3bf35d01e4fd0703e47d538bd8cec03652b.tar.bz2 SMAPI-dd27b3bf35d01e4fd0703e47d538bd8cec03652b.zip |
fix parsing four-part versions from the update-check API
Diffstat (limited to 'src/SMAPI.Web')
-rw-r--r-- | src/SMAPI.Web/Controllers/ModsApiController.cs | 22 | ||||
-rw-r--r-- | src/SMAPI.Web/Framework/VersionConstraint.cs | 2 |
2 files changed, 6 insertions, 18 deletions
diff --git a/src/SMAPI.Web/Controllers/ModsApiController.cs b/src/SMAPI.Web/Controllers/ModsApiController.cs index 8370fe09..06768f03 100644 --- a/src/SMAPI.Web/Controllers/ModsApiController.cs +++ b/src/SMAPI.Web/Controllers/ModsApiController.cs @@ -296,7 +296,7 @@ namespace StardewModdingAPI.Web.Controllers { if (result.Version == null) result.SetError(RemoteModStatus.InvalidData, $"The update key '{updateKey}' matches a mod with no version number."); - else if (!this.TryParseVersion(result.Version, allowNonStandardVersions, out _)) + else if (!SemanticVersion.TryParse(result.Version, allowNonStandardVersions, out _)) result.SetError(RemoteModStatus.InvalidData, $"The update key '{updateKey}' matches a mod with invalid semantic version '{result.Version}'."); } @@ -360,11 +360,11 @@ namespace StardewModdingAPI.Web.Controllers { // try mapped version string rawNewVersion = this.GetRawMappedVersion(version, map, allowNonStandard); - if (this.TryParseVersion(rawNewVersion, allowNonStandard, out ISemanticVersion parsedNew)) + if (SemanticVersion.TryParse(rawNewVersion, allowNonStandard, out ISemanticVersion parsedNew)) return parsedNew; // return original version - return this.TryParseVersion(version, allowNonStandard, out ISemanticVersion parsedOld) + return SemanticVersion.TryParse(version, allowNonStandard, out ISemanticVersion parsedOld) ? parsedOld : null; } @@ -383,31 +383,19 @@ namespace StardewModdingAPI.Web.Controllers return map[version]; // match parsed version - if (this.TryParseVersion(version, allowNonStandard, out ISemanticVersion parsed)) + if (SemanticVersion.TryParse(version, allowNonStandard, out ISemanticVersion parsed)) { if (map.ContainsKey(parsed.ToString())) return map[parsed.ToString()]; foreach (var pair in map) { - if (this.TryParseVersion(pair.Key, allowNonStandard, out ISemanticVersion target) && parsed.Equals(target) && this.TryParseVersion(pair.Value, allowNonStandard, out ISemanticVersion newVersion)) + if (SemanticVersion.TryParse(pair.Key, allowNonStandard, out ISemanticVersion target) && parsed.Equals(target) && SemanticVersion.TryParse(pair.Value, allowNonStandard, out ISemanticVersion newVersion)) return newVersion.ToString(); } } return version; } - - /// <summary>Try to parse a version string.</summary> - /// <param name="version">The version string.</param> - /// <param name="allowNonStandard">Whether to allow non-standard versions.</param> - /// <param name="parsed">The parsed representation.</param> - /// <returns>Returns whether parsing the version succeeded.</returns> - public bool TryParseVersion(string version, bool allowNonStandard, out ISemanticVersion parsed) - { - return allowNonStandard - ? SemanticVersion.TryParseNonStandard(version, out parsed) - : SemanticVersion.TryParse(version, out parsed); - } } } diff --git a/src/SMAPI.Web/Framework/VersionConstraint.cs b/src/SMAPI.Web/Framework/VersionConstraint.cs index 72f5ef84..f0c57c41 100644 --- a/src/SMAPI.Web/Framework/VersionConstraint.cs +++ b/src/SMAPI.Web/Framework/VersionConstraint.cs @@ -28,7 +28,7 @@ namespace StardewModdingAPI.Web.Framework return values.TryGetValue(routeKey, out object routeValue) && routeValue is string routeStr - && SemanticVersion.TryParseNonStandard(routeStr, out _); + && SemanticVersion.TryParse(routeStr, allowNonStandard: true, out _); } } } |