Change containment check to overlap

Due to scenarios wherein a formatted link ended up as part of a larger
raw link after parsing, change the containment check to an overlap check
and add appropriate tests for these edge cases.
This commit is contained in:
Bartłomiej Dach
2019-10-25 00:20:44 +02:00
parent cbd99cc767
commit 661dfbefaf
2 changed files with 32 additions and 2 deletions

View File

@ -104,7 +104,7 @@ namespace osu.Game.Online.Chat
// sometimes an already-processed formatted link can reduce to a simple URL, too
// (example: [mean example - https://osu.ppy.sh](https://osu.ppy.sh))
// therefore we need to check if any of the pre-existing links contains the raw one we found
if (result.Links.All(existingLink => !existingLink.Contains(link)))
if (result.Links.All(existingLink => !existingLink.Overlaps(link)))
result.Links.Add(link);
}
}
@ -298,7 +298,7 @@ namespace osu.Game.Online.Chat
Argument = argument;
}
public bool Contains(Link otherLink) => otherLink.Index >= Index && otherLink.Index + otherLink.Length <= Index + Length;
public bool Overlaps(Link otherLink) => Index < otherLink.Index + otherLink.Length && otherLink.Index < Index + Length;
public int CompareTo(Link otherLink) => Index > otherLink.Index ? 1 : -1;
}