diff options
author | atravita-mods <94934860+atravita-mods@users.noreply.github.com> | 2022-10-16 18:04:19 -0400 |
---|---|---|
committer | atravita-mods <94934860+atravita-mods@users.noreply.github.com> | 2022-10-16 18:04:19 -0400 |
commit | 4dcc6904b9e72ac3567dfafe3824c2de48218b58 (patch) | |
tree | 27f1fd4f06be1aa544426601d399c93193a1b546 | |
parent | 573f732c2a2118d7a4848151764df6bef1a47008 (diff) | |
download | SMAPI-4dcc6904b9e72ac3567dfafe3824c2de48218b58.tar.gz SMAPI-4dcc6904b9e72ac3567dfafe3824c2de48218b58.tar.bz2 SMAPI-4dcc6904b9e72ac3567dfafe3824c2de48218b58.zip |
fix issues with subfolders
-rw-r--r-- | src/SMAPI.Tests/Core/AssetNameTests.cs | 14 | ||||
-rw-r--r-- | src/SMAPI.Tests/SMAPI.Tests.csproj | 1 | ||||
-rw-r--r-- | src/SMAPI/Framework/Content/AssetName.cs | 8 |
3 files changed, 19 insertions, 4 deletions
diff --git a/src/SMAPI.Tests/Core/AssetNameTests.cs b/src/SMAPI.Tests/Core/AssetNameTests.cs index 655e9bae..fe70e330 100644 --- a/src/SMAPI.Tests/Core/AssetNameTests.cs +++ b/src/SMAPI.Tests/Core/AssetNameTests.cs @@ -243,6 +243,20 @@ namespace SMAPI.Tests.Core return result; } + [TestCase("Mods/SomeMod/SomeSubdirectory", "Mods/Some", true, ExpectedResult = true)] + [TestCase("Mods/SomeMod/SomeSubdirectory", "Mods/Some", false, ExpectedResult = false)] + public bool StartsWith_SubfolderWithPartial(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.Tests/SMAPI.Tests.csproj b/src/SMAPI.Tests/SMAPI.Tests.csproj index 2c32a932..597cd7dd 100644 --- a/src/SMAPI.Tests/SMAPI.Tests.csproj +++ b/src/SMAPI.Tests/SMAPI.Tests.csproj @@ -19,6 +19,7 @@ <PackageReference Include="Moq" Version="4.18.1" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.1" /> <PackageReference Include="NUnit" Version="3.13.3" /> + <PackageReference Include="NUnit3TestAdapter" Version="4.2.1" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" /> </ItemGroup> <ItemGroup> diff --git a/src/SMAPI/Framework/Content/AssetName.cs b/src/SMAPI/Framework/Content/AssetName.cs index bdb79dde..9d59f222 100644 --- a/src/SMAPI/Framework/Content/AssetName.cs +++ b/src/SMAPI/Framework/Content/AssetName.cs @@ -162,8 +162,8 @@ namespace StardewModdingAPI.Framework.Content if (prefixHasMore) return false; - // possible match: all prefix segments matched - return allowSubfolder || !curParts.Remainder.Contains(pathSeparators, StringComparison.Ordinal); + // possible match: all prefix segments matched. + return allowSubfolder || (pathSeparators.Contains(trimmed[^1]) ? curParts.Remainder.Length == 0 : curParts.Current.Length == 0); } // match: previous segments matched exactly and both reached the end @@ -192,7 +192,7 @@ namespace StardewModdingAPI.Framework.Content return false; // possible match - return allowSubfolder || !curParts.Remainder.Contains(pathSeparators, StringComparison.Ordinal); + return allowSubfolder || (pathSeparators.Contains(trimmed[^1]) ? curParts.Remainder.IndexOfAny(ToolkitPathUtilities.PossiblePathSeparators) < 0 : curParts.Remainder.Length == 0); } } } @@ -203,7 +203,7 @@ namespace StardewModdingAPI.Framework.Content if (assetFolder is null) return false; - return this.StartsWith(assetFolder + "/", allowPartialWord: false, allowSubfolder: false); + return this.StartsWith(assetFolder + ToolkitPathUtilities.PreferredPathSeparator, allowPartialWord: false, allowSubfolder: false); } /// <inheritdoc /> |