Skip to content

Commit

Permalink
Fixed: Parsing similar artist names with common words at end
Browse files Browse the repository at this point in the history
(cherry picked from commit 0fe24539625f8397dfb63d4618611db99c3c137a)

Closes #2064
  • Loading branch information
markus101 authored and mynameisbogdan committed Dec 22, 2023
1 parent 234d277 commit 3dd933b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
28 changes: 23 additions & 5 deletions src/NzbDrone.Core.Test/ParserTests/NormalizeTitleFixture.cs
Expand Up @@ -35,16 +35,13 @@ public void should_remove_special_characters_and_casing(string dirty, string cle
[TestCase("or")]
[TestCase("an")]
[TestCase("of")]
public void should_remove_common_words(string word)
public void should_remove_common_words_from_middle_of_title(string word)
{
var dirtyFormat = new[]
{
"word.{0}.word",
"word {0} word",
"word-{0}-word",
"word.word.{0}",
"word-word-{0}",
"word-word {0}",
"word-{0}-word"
};

foreach (var s in dirtyFormat)
Expand All @@ -54,6 +51,27 @@ public void should_remove_common_words(string word)
}
}

[TestCase("the")]
[TestCase("and")]
[TestCase("or")]
[TestCase("an")]
[TestCase("of")]
public void should_not_remove_common_words_from_end_of_title(string word)
{
var dirtyFormat = new[]
{
"word.word.{0}",
"word-word-{0}",
"word-word {0}"
};

foreach (var s in dirtyFormat)
{
var dirty = string.Format(s, word);
dirty.CleanArtistName().Should().Be("wordword" + word.ToLower());
}
}

[Test]
public void should_remove_a_from_middle_of_title()
{
Expand Down
2 changes: 1 addition & 1 deletion src/NzbDrone.Core/Parser/Parser.cs
Expand Up @@ -154,7 +154,7 @@ public static class Parser
new Regex(@"^b00bs$", RegexOptions.Compiled | RegexOptions.IgnoreCase)
};

private static readonly RegexReplace NormalizeRegex = new RegexReplace(@"((?:\b|_)(?<!^)(a(?!$)|an|the|and|or|of)(?:\b|_))|\W|_",
private static readonly RegexReplace NormalizeRegex = new RegexReplace(@"((?:\b|_)(?<!^)(a(?!$)|an|the|and|or|of)(?!$)(?:\b|_))|\W|_",
string.Empty,
RegexOptions.IgnoreCase | RegexOptions.Compiled);

Expand Down

0 comments on commit 3dd933b

Please sign in to comment.