From a0a72e310d29bb9148e4c33a058823cd33bbb98d Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Mon, 30 Oct 2017 19:26:45 -0400 Subject: explicitly disallow absolute paths as asset keys in content API (#381) --- docs/release-notes.md | 7 ++++--- src/SMAPI/Framework/ModHelpers/ContentHelper.cs | 14 +++++++++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/docs/release-notes.md b/docs/release-notes.md index 6a827b0f..2a50c045 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -19,9 +19,10 @@ * Fixed `e.SuppressButton()` not correctly suppressing keyboard buttons. * Fixed `e.IsClick` (now `e.IsActionButton`) ignoring custom key bindings. * `SemanticVersion` can now be constructed from a `System.Version`. - * Fixed custom map tilesheets not working unless they're explicitly loaded first. - * Fixed mods which implement `IAssetLoader` directly not being allowed to load files due to incorrect conflict detection. - * Fixed SMAPI blocking reflection access to vanilla members on overridden types. + * Fixed reflection API blocking access to vanilla members on overridden types. + * Fixed content API allowing absolute paths as asset keys. + * Fixed content API failing to load custom map tilesheets that aren't preloaded. + * Fixed content API incorrectly detecting duplicate loaders when a mod implements `IAssetLoader` directly. * For SMAPI developers: * Added the SMAPI installer version and platform to the window title to simplify troubleshooting. diff --git a/src/SMAPI/Framework/ModHelpers/ContentHelper.cs b/src/SMAPI/Framework/ModHelpers/ContentHelper.cs index 711897eb..be9594ee 100644 --- a/src/SMAPI/Framework/ModHelpers/ContentHelper.cs +++ b/src/SMAPI/Framework/ModHelpers/ContentHelper.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Diagnostics.CodeAnalysis; using System.IO; using System.Linq; using Microsoft.Xna.Framework.Content; @@ -88,7 +89,7 @@ namespace StardewModdingAPI.Framework.ModHelpers try { - this.ContentManager.AssertValidAssetKeyFormat(key); + this.AssertValidAssetKeyFormat(key); switch (source) { case ContentSource.GameContent: @@ -189,6 +190,17 @@ namespace StardewModdingAPI.Framework.ModHelpers /********* ** Private methods *********/ + /// Assert that the given key has a valid format. + /// The asset key to check. + /// The asset key is empty or contains invalid characters. + [SuppressMessage("ReSharper", "ParameterOnlyUsedForPreconditionCheck.Local", Justification = "Parameter is only used for assertion checks by design.")] + private void AssertValidAssetKeyFormat(string key) + { + this.ContentManager.AssertValidAssetKeyFormat(key); + if (Path.IsPathRooted(key)) + throw new ArgumentException("The asset key must not be an absolute path."); + } + /// Fix custom map tilesheet paths so they can be found by the content manager. /// The map whose tilesheets to fix. /// The map asset key within the mod folder. -- cgit