enforce mod ID convention (only alphanumeric, hyphen, dot, and underscore)

This commit is contained in:
Jesse Plamondon-Willard 2018-05-05 22:18:52 -04:00
parent 30bf40ab2b
commit 5121ae7b4a
2 changed files with 12 additions and 3 deletions

View File

@ -27,9 +27,10 @@
* Fixed console command input not saved to the log.
* Fixed `helper.ModRegistry.GetApi` interface validation errors not mentioning which interface caused the issue.
* **Breaking changes** (see [migration guide](https://stardewvalleywiki.com/Modding:Migrate_to_Stardew_Valley_1.3)):
* dropped some deprecated APIs;
* `LocationEvents` have been rewritten (see above);
* mods can't intercept chatbox input, including the game's hotkeys to toggle the chatbox (default `T` and `?`).
* Dropped some deprecated APIs.
* `LocationEvents` have been rewritten (see above).
* Mods can't intercept chatbox input, including the game's hotkeys to toggle the chatbox (default `T` and `?`).
* Mod IDs should only contain letters, numbers, hyphens, dots, and underscores (so they can be safely used in many contexts like URLs); this restriction is now enforced.
* In console commands:
* Added `player_add name`, which lets you add items to your inventory by name instead of ID.

View File

@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using StardewModdingAPI.Framework.Exceptions;
using StardewModdingAPI.Framework.ModData;
using StardewModdingAPI.Framework.Models;
@ -194,8 +195,15 @@ namespace StardewModdingAPI.Framework.ModLoading
missingFields.Add(nameof(IManifest.UniqueID));
if (missingFields.Any())
{
mod.SetStatus(ModMetadataStatus.Failed, $"its manifest is missing required fields ({string.Join(", ", missingFields)}).");
continue;
}
}
// validate ID format
if (Regex.IsMatch(mod.Manifest.UniqueID, "[^a-z0-9_.-]", RegexOptions.IgnoreCase))
mod.SetStatus(ModMetadataStatus.Failed, "its manifest specifies an invalid ID (IDs must only contain letters, numbers, underscores, periods, or hyphens).");
}
// validate IDs are unique