mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-22 22:14:44 -04:00
Moved trakt search term tests to non-integration test. Added several more testcases for the camelCase conversion and adjusted the underlying logic accordingly.
This commit is contained in:
@@ -19,8 +19,8 @@ namespace NzbDrone.Core.MetadataSource
|
||||
private readonly IHttpClient _httpClient;
|
||||
private static readonly Regex CollapseSpaceRegex = new Regex(@"\s+", RegexOptions.Compiled);
|
||||
private static readonly Regex InvalidSearchCharRegex = new Regex(@"(?:\*|\(|\)|'|!|@|\+)", RegexOptions.Compiled);
|
||||
private static readonly Regex ExpandCamelCaseRegEx = new Regex(@"(?<!^|[A-Z]\.?|[^\w.])(?=[A-Z])", RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled);
|
||||
|
||||
private static readonly Regex ExpandCamelCaseRegEx = new Regex(@"(?<!^|[A-Z]\.?|[^\w.])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])|(?<!^|\d\.?|[^\w.])(?=\d)", RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled);
|
||||
|
||||
private readonly HttpRequestBuilder _requestBuilder;
|
||||
|
||||
public TraktProxy(Logger logger, IHttpClient httpClient)
|
||||
@@ -230,12 +230,18 @@ namespace NzbDrone.Core.MetadataSource
|
||||
}
|
||||
|
||||
private static string GetSearchTerm(string phrase)
|
||||
{
|
||||
{
|
||||
phrase = phrase.RemoveAccent();
|
||||
phrase = InvalidSearchCharRegex.Replace(phrase, "");
|
||||
phrase = ExpandCamelCaseRegEx.Replace(phrase, " ");
|
||||
|
||||
if (!phrase.Any(char.IsWhiteSpace) && phrase.Any(char.IsUpper) && phrase.Any(char.IsLower) && phrase.Length > 4)
|
||||
{
|
||||
phrase = ExpandCamelCaseRegEx.Replace(phrase, " ");
|
||||
}
|
||||
|
||||
phrase = CollapseSpaceRegex.Replace(phrase, " ").Trim();
|
||||
phrase = phrase.Trim('-');
|
||||
|
||||
phrase = System.Web.HttpUtility.UrlEncode(phrase.ToLower());
|
||||
|
||||
return phrase;
|
||||
|
||||
Reference in New Issue
Block a user