summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI.Web/Controllers
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-09-24 01:30:28 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-09-24 01:30:28 -0400
commit00957a23177f792d4e4962854697779831d51ca1 (patch)
treec603edd9f4a7e7a2ab8f35efbe1cbd523cb01c2f /src/StardewModdingAPI.Web/Controllers
parentd3f0c8e4d2d9ada099cba67c359c5df1d69a1257 (diff)
downloadSMAPI-00957a23177f792d4e4962854697779831d51ca1.tar.gz
SMAPI-00957a23177f792d4e4962854697779831d51ca1.tar.bz2
SMAPI-00957a23177f792d4e4962854697779831d51ca1.zip
validate semantic versions in API (#336, #361)
Diffstat (limited to 'src/StardewModdingAPI.Web/Controllers')
-rw-r--r--src/StardewModdingAPI.Web/Controllers/ModsController.cs10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/StardewModdingAPI.Web/Controllers/ModsController.cs b/src/StardewModdingAPI.Web/Controllers/ModsController.cs
index c5c79600..4eaa66d2 100644
--- a/src/StardewModdingAPI.Web/Controllers/ModsController.cs
+++ b/src/StardewModdingAPI.Web/Controllers/ModsController.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Memory;
@@ -27,6 +28,9 @@ namespace StardewModdingAPI.Web.Controllers
/// <summary>The number of minutes update checks should be cached before refetching them.</summary>
private readonly int CacheMinutes;
+ /// <summary>A regex which matches SMAPI-style semantic version.</summary>
+ private readonly string VersionRegex;
+
/*********
** Public methods
@@ -40,6 +44,7 @@ namespace StardewModdingAPI.Web.Controllers
this.Cache = cache;
this.CacheMinutes = config.CacheMinutes;
+ this.VersionRegex = config.SemanticVersionRegex;
string version = this.GetType().Assembly.GetName().Version.ToString(3);
this.Repositories =
@@ -103,7 +108,10 @@ namespace StardewModdingAPI.Web.Controllers
result[modKey] = await this.Cache.GetOrCreateAsync($"{repository.VendorKey}:{modID}".ToLower(), async entry =>
{
entry.AbsoluteExpiration = DateTimeOffset.UtcNow.AddMinutes(this.CacheMinutes);
- return await repository.GetModInfoAsync(modID);
+ ModInfoModel info = await repository.GetModInfoAsync(modID);
+ if (info.Error == null && !Regex.IsMatch(info.Version, this.VersionRegex, RegexOptions.CultureInvariant | RegexOptions.IgnoreCase))
+ info = new ModInfoModel(info.Name, info.Version, info.Url, $"Mod has invalid semantic version '{info.Version}'.");
+ return info;
});
}