Fixed ContainsAny method so that it uses the passed in Comparison method (which enabled case-insensitive comparisons to work)

This commit is contained in:
Dan Booth
2018-05-10 14:28:16 +01:00
parent 324cd7e98f
commit 3f35eca999

View File

@@ -121,8 +121,8 @@ namespace Umbraco.Core
//if the resolution was success, return it, otherwise just return the path, we've detected
// it's a path but maybe it's relative and resolution has failed, etc... in which case we're just
// returning what was given to us.
return resolvedUrlResult.Success
? resolvedUrlResult
return resolvedUrlResult.Success
? resolvedUrlResult
: Attempt.Succeed(input);
}
}
@@ -144,7 +144,7 @@ namespace Umbraco.Core
}
internal static readonly Regex Whitespace = new Regex(@"\s+", RegexOptions.Compiled);
internal static readonly string[] JsonEmpties = new [] { "[]", "{}" };
internal static readonly string[] JsonEmpties = new[] { "[]", "{}" };
internal static bool DetectIsEmptyJson(this string input)
{
return JsonEmpties.Contains(Whitespace.Replace(input, string.Empty));
@@ -1436,14 +1436,25 @@ namespace Umbraco.Core
return ReplaceMany(text, regexSpecialCharacters);
}
/// <summary>
/// Checks whether a string "haystack" contains within it any of the strings in the "needles" collection and returns true if it does or false if it doesn't
/// </summary>
/// <param name="haystack">The string to check</param>
/// <param name="needles">The collection of strings to check are contained within the first string</param>
/// <param name="comparison">The type of comparision to perform - defaults to <see cref="StringComparison.CurrentCulture"/></param>
/// <returns>True if any of the needles are contained with haystack; otherwise returns false</returns>
/// Added fix to ensure the comparison is used - see http://issues.umbraco.org/issue/U4-11313
public static bool ContainsAny(this string haystack, IEnumerable<string> needles, StringComparison comparison = StringComparison.CurrentCulture)
{
if (haystack == null) throw new ArgumentNullException("haystack");
if (string.IsNullOrEmpty(haystack) == false || needles.Any())
if (haystack == null)
throw new ArgumentNullException("haystack");
if (string.IsNullOrEmpty(haystack) || needles == null || !needles.Any())
{
return needles.Any(value => haystack.IndexOf(value) >= 0);
return false;
}
return false;
return needles.Any(value => haystack.IndexOf(value, comparison) >= 0);
}
public static bool CsvContains(this string csv, string value)