add validation for the manifest 'Dependencies' field

This commit is contained in:
Jesse Plamondon-Willard 2021-05-09 12:13:39 -04:00
parent 4b391d631c
commit 7c76c5cad2
No known key found for this signature in database
GPG Key ID: CF8B1456B3E29F49
2 changed files with 23 additions and 0 deletions

View File

@ -9,6 +9,7 @@
## Upcoming release ## Upcoming release
* For mod authors: * For mod authors:
* Added validation for the manifest `Dependencies` field.
* Fixed validation for mods with version `0.0.0`. * Fixed validation for mods with version `0.0.0`.
## 3.10.1 ## 3.10.1

View File

@ -188,6 +188,28 @@ namespace StardewModdingAPI.Framework.ModLoading
// validate ID format // validate ID format
if (!PathUtilities.IsSlug(mod.Manifest.UniqueID)) if (!PathUtilities.IsSlug(mod.Manifest.UniqueID))
mod.SetStatus(ModMetadataStatus.Failed, ModFailReason.InvalidManifest, "its manifest specifies an invalid ID (IDs must only contain letters, numbers, underscores, periods, or hyphens)."); mod.SetStatus(ModMetadataStatus.Failed, ModFailReason.InvalidManifest, "its manifest specifies an invalid ID (IDs must only contain letters, numbers, underscores, periods, or hyphens).");
// validate dependencies
foreach (var dependency in mod.Manifest.Dependencies)
{
// null dependency
if (dependency == null)
{
mod.SetStatus(ModMetadataStatus.Failed, ModFailReason.InvalidManifest, $"its manifest has a null entry under {nameof(IManifest.Dependencies)}.");
continue;
}
// missing ID
if (string.IsNullOrWhiteSpace(dependency.UniqueID))
{
mod.SetStatus(ModMetadataStatus.Failed, ModFailReason.InvalidManifest, $"its manifest has a {nameof(IManifest.Dependencies)} entry with no {nameof(IManifestDependency.UniqueID)} field.");
continue;
}
// invalid ID
if (!PathUtilities.IsSlug(dependency.UniqueID))
mod.SetStatus(ModMetadataStatus.Failed, ModFailReason.InvalidManifest, $"its manifest has a {nameof(IManifest.Dependencies)} entry with an invalid {nameof(IManifestDependency.UniqueID)} field (IDs must only contain letters, numbers, underscores, periods, or hyphens).");
}
} }
// validate IDs are unique // validate IDs are unique