fix index-out-of-range error when StartsWith prefix is empty

This commit is contained in:
Jesse Plamondon-Willard 2022-10-16 14:41:45 -04:00
parent eed1deb3c7
commit 4e3b2810e6
No known key found for this signature in database
GPG Key ID: CF8B1456B3E29F49
1 changed files with 6 additions and 8 deletions

View File

@ -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();