diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2022-10-16 14:41:45 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2022-10-16 14:41:45 -0400 |
commit | 4e3b2810e6951b72bdf5c5cbdd23a079d53a4c96 (patch) | |
tree | 09abfaa6272e1082c3a9a0452454f7b9694c8a57 /src/SMAPI/Framework/Content/AssetName.cs | |
parent | eed1deb3c75ba2aeea94ea9a57f9fe7ad92a90ce (diff) | |
download | SMAPI-4e3b2810e6951b72bdf5c5cbdd23a079d53a4c96.tar.gz SMAPI-4e3b2810e6951b72bdf5c5cbdd23a079d53a4c96.tar.bz2 SMAPI-4e3b2810e6951b72bdf5c5cbdd23a079d53a4c96.zip |
fix index-out-of-range error when StartsWith prefix is empty
Diffstat (limited to 'src/SMAPI/Framework/Content/AssetName.cs')
-rw-r--r-- | src/SMAPI/Framework/Content/AssetName.cs | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/src/SMAPI/Framework/Content/AssetName.cs b/src/SMAPI/Framework/Content/AssetName.cs index d7ee6dba..c0572105 100644 --- a/src/SMAPI/Framework/Content/AssetName.cs +++ b/src/SMAPI/Framework/Content/AssetName.cs @@ -139,21 +139,19 @@ namespace StardewModdingAPI.Framework.Content if (prefix is null) return false; + // get initial values ReadOnlySpan<char> trimmed = prefix.AsSpan().Trim(); + if (trimmed.Length == 0) + return true; + ReadOnlySpan<char> pathSeparators = new(ToolkitPathUtilities.PossiblePathSeparators); // just to simplify calling other span APIs - // just because most ReadOnlySpan/Span APIs expect a ReadOnlySpan/Span, easier to read. - ReadOnlySpan<char> pathSeparators = new(ToolkitPathUtilities.PossiblePathSeparators); - - // asset keys can't have a leading slash, but AssetPathYielder won't yield that. + // asset keys can't have a leading slash, but AssetPathYielder will trim them if (pathSeparators.Contains(trimmed[0])) return false; - if (trimmed.Length == 0) - return true; - + // compare segments AssetNamePartEnumerator curParts = new(this.Name); AssetNamePartEnumerator prefixParts = new(trimmed); - while (true) { bool prefixHasMore = prefixParts.MoveNext(); |