summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/SMAPI.Tests/Core/AssetNameTests.cs20
-rw-r--r--src/SMAPI/Framework/Content/AssetName.cs2
2 files changed, 21 insertions, 1 deletions
diff --git a/src/SMAPI.Tests/Core/AssetNameTests.cs b/src/SMAPI.Tests/Core/AssetNameTests.cs
index fdaa2c01..cd4d0473 100644
--- a/src/SMAPI.Tests/Core/AssetNameTests.cs
+++ b/src/SMAPI.Tests/Core/AssetNameTests.cs
@@ -265,6 +265,26 @@ namespace SMAPI.Tests.Core
return name.StartsWith(otherAssetName, allowPartialWord: true, allowSubfolder: allowSubfolder);
}
+ // the enumerator strips the trailing path seperator
+ // so each of these cases has to be handled on each branch.
+ [TestCase("Mods/SomeMod", "Mods/", false, ExpectedResult = true)]
+ [TestCase("Mods/SomeMod", "Mods", false, ExpectedResult = false)]
+ [TestCase("Mods/Jasper/Data", "Mods/Jas/", false, ExpectedResult = false)]
+ [TestCase("Mods/Jasper/Data", "Mods/Jas", false, ExpectedResult = false)]
+ [TestCase("Mods/Jas", "Mods/Jas/", false, ExpectedResult = false)]
+ [TestCase("Mods/Jas", "Mods/Jas", false, ExpectedResult = true)]
+ public bool StartsWith_PrefixHasSeperator(string mainAssetName, string otherAssetName, bool allowSubfolder)
+ {
+ // arrange
+ mainAssetName = PathUtilities.NormalizeAssetName(mainAssetName);
+
+ // act
+ AssetName name = AssetName.Parse(mainAssetName, _ => null);
+
+ // assert value
+ return name.StartsWith(otherAssetName, allowPartialWord: true, allowSubfolder: allowSubfolder);
+ }
+
/****
** GetHashCode
diff --git a/src/SMAPI/Framework/Content/AssetName.cs b/src/SMAPI/Framework/Content/AssetName.cs
index 99968299..83593de8 100644
--- a/src/SMAPI/Framework/Content/AssetName.cs
+++ b/src/SMAPI/Framework/Content/AssetName.cs
@@ -163,7 +163,7 @@ namespace StardewModdingAPI.Framework.Content
return false;
// match if subfolder paths are fine (e.g. prefix 'Data/Events' with target 'Data/Events/Beach')
- return allowSubfolder;
+ return allowSubfolder || (pathSeparators.Contains(trimmedPrefix[^1]) && curParts.Remainder.Length == 0);
}
// previous segments matched exactly and both reached the end