Skip to content

Commit

Permalink
Optimize ContainsEscapedWildcards to do the work in one pass
Browse files Browse the repository at this point in the history
  • Loading branch information
ladipro committed Mar 5, 2021
1 parent abdbd9f commit a1f33c2
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions src/Shared/EscapingUtilities.cs
Expand Up @@ -226,28 +226,22 @@ string unescapedString
/// </summary>
/// <param name="escapedString"></param>
/// <returns></returns>
internal static bool ContainsEscapedWildcards
(
string escapedString
)
internal static bool ContainsEscapedWildcards(string escapedString)
{
if (-1 != escapedString.IndexOf('%'))
int index = escapedString.IndexOf('%', 0, escapedString.Length - 2);
while (index != -1)
{
// It has a '%' sign. We have promise.
if (
(-1 != escapedString.IndexOf("%2", StringComparison.Ordinal)) ||
(-1 != escapedString.IndexOf("%3", StringComparison.Ordinal))
)
if (escapedString[index + 1] == '2' && (escapedString[index + 2] == 'a' || escapedString[index + 2] == 'A'))
{
// %2a or %2A
return true;
}
if (escapedString[index + 1] == '3' && (escapedString[index + 2] == 'f' || escapedString[index + 2] == 'F'))
{
// It has either a '%2' or a '%3'. This is looking very promising.
return

(-1 != escapedString.IndexOf("%2a", StringComparison.Ordinal)) ||
(-1 != escapedString.IndexOf("%2A", StringComparison.Ordinal)) ||
(-1 != escapedString.IndexOf("%3f", StringComparison.Ordinal)) ||
(-1 != escapedString.IndexOf("%3F", StringComparison.Ordinal))
;
// %3f or %3F
return true;
}
index = escapedString.IndexOf('%', index + 1, escapedString.Length - index - 3);
}
return false;
}
Expand Down

0 comments on commit a1f33c2

Please sign in to comment.