From 84ad8b2a92eac9155cada821c57d62a517b958a8 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 4 Aug 2019 20:13:10 -0400 Subject: fix manifest error if neither EntryDll nor ContentPackFor are specified (#654) --- .../Controllers/JsonValidatorController.cs | 26 +++++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'src/SMAPI.Web/Controllers') diff --git a/src/SMAPI.Web/Controllers/JsonValidatorController.cs b/src/SMAPI.Web/Controllers/JsonValidatorController.cs index 7b755d3b..b69a1006 100644 --- a/src/SMAPI.Web/Controllers/JsonValidatorController.cs +++ b/src/SMAPI.Web/Controllers/JsonValidatorController.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Text.RegularExpressions; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; @@ -176,7 +177,7 @@ namespace StardewModdingAPI.Web.Controllers private string GetFlattenedError(ValidationError error, int indent = 0) { // get override error - string message = this.GetOverrideError(error.Schema, error.ErrorType); + string message = this.GetOverrideError(error.Schema, error.ErrorType, error.Message); if (message != null) return message; @@ -232,7 +233,8 @@ namespace StardewModdingAPI.Web.Controllers /// Get an override error from the JSON schema, if any. /// The schema or subschema that raised the error. /// The error type. - private string GetOverrideError(JSchema schema, ErrorType errorType) + /// The error message. + private string GetOverrideError(JSchema schema, ErrorType errorType, string message) { // get override errors IDictionary errors = this.GetExtensionField>(schema, "@errorMessages"); @@ -240,10 +242,22 @@ namespace StardewModdingAPI.Web.Controllers return null; errors = new Dictionary(errors, StringComparer.InvariantCultureIgnoreCase); - // get matching error - return errors.TryGetValue(errorType.ToString(), out string errorPhrase) - ? errorPhrase - : null; + // match error by type and message + foreach (var pair in errors) + { + if (!pair.Key.Contains(":")) + continue; + + string[] parts = pair.Key.Split(':', 2); + if (parts[0].Equals(errorType.ToString(), StringComparison.InvariantCultureIgnoreCase) && Regex.IsMatch(message, parts[1])) + return pair.Value; + } + + // match by type + if (errors.TryGetValue(errorType.ToString(), out string error)) + return error; + + return null; } /// Get an extension field from a JSON schema. -- cgit