summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/Content
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-11-11 21:25:01 -0500
committerGitHub <noreply@github.com>2022-11-11 21:25:01 -0500
commit1894cd831e2f31cbdb0baab63ea3638b4b62ff52 (patch)
tree780706844d5eef82d4af8097a76fa657125d2c40 /src/SMAPI/Framework/Content
parenta52f888c3f7098eb06f4ae2e6a3a5b1998470d15 (diff)
parentad2dcc28791eb8026335646474fb2e0766fcc51b (diff)
downloadSMAPI-1894cd831e2f31cbdb0baab63ea3638b4b62ff52.tar.gz
SMAPI-1894cd831e2f31cbdb0baab63ea3638b4b62ff52.tar.bz2
SMAPI-1894cd831e2f31cbdb0baab63ea3638b4b62ff52.zip
Merge pull request #884 from atravita-mods/develop
AssetName.StartsWith - fix yet another case with the trailing slash
Diffstat (limited to 'src/SMAPI/Framework/Content')
-rw-r--r--src/SMAPI/Framework/Content/AssetName.cs10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/SMAPI/Framework/Content/AssetName.cs b/src/SMAPI/Framework/Content/AssetName.cs
index 99968299..8355f9ec 100644
--- a/src/SMAPI/Framework/Content/AssetName.cs
+++ b/src/SMAPI/Framework/Content/AssetName.cs
@@ -162,8 +162,14 @@ namespace StardewModdingAPI.Framework.Content
if (prefixHasMore)
return false;
- // match if subfolder paths are fine (e.g. prefix 'Data/Events' with target 'Data/Events/Beach')
- return allowSubfolder;
+ // match: every segment in the prefix matched and subfolders are allowed (e.g. prefix 'Data/Events' with target 'Data/Events/Beach')
+ if (allowSubfolder)
+ return true;
+
+ // Special case: the prefix ends with a path separator, but subfolders aren't allowed. This case
+ // matches if there's no further path separator in the asset name *after* the current separator.
+ // For example, the prefix 'A/B/' matches 'A/B/C' but not 'A/B/C/D'.
+ return pathSeparators.Contains(trimmedPrefix[^1]) && curParts.Remainder.Length == 0;
}
// previous segments matched exactly and both reached the end